tillahoffmann / obsidian-jupyter

MIT License
438 stars 23 forks source link

Server not sending a response with plotly #19

Closed BlackFireAlex closed 3 years ago

BlackFireAlex commented 3 years ago

The server doesn't send a response when I try to plot something with plotly:

The console gets stuck with this

INFO:obsidian-jupyter:received request: {"id":"32ab9e53-1c13-4ed8-8634-7dfd00a303de","body":{"command":"execute","source":"\nimport chart_studio.plotly as py\nimport plotly.graph_objects as go\n\ndata = [go.Bar(x=df.School,\n            y=df.Gap)]\n\npy.iplot(data, filename='jupyter-basic_bar')\n\n"}}

INFO:traitlets:Executing notebook with kernel: 

And I can't run code after that

tillahoffmann commented 3 years ago

Could you please post a minimal reproducible example that works in a standard jupyter notebook but fails using the plugin?

BlackFireAlex commented 3 years ago
import plotly.graph_objects as go
fig = go.Figure(
    data=[go.Bar(y=[2, 1, 3])],
    layout_title_text="A Figure Displayed with fig.show()"
)
fig.show()

This work perfectly in Jupyter Serveer or Pycharm

tillahoffmann commented 3 years ago

It looks like this isn't working because the plugin doesn't execute javascript contained within the response. However, even when executing said script, the above example fails with Uncaught TypeError: require.undef is not a function which might be a problem with the right javascript libraries being available (or not) for plotly. Are you familiar enough with plotly to comment on that issue?

BlackFireAlex commented 3 years ago

Sorry for the late reply. Could you try this alternate version and tell me how it goes ? All the needed imports are listed here

import plotly.offline as py
import plotly.graph_objs as go
import plotly.figure_factory as ff
import pandas as pd
py.init_notebook_mode(connected=True)

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/school_earnings.csv")

table = ff.create_table(df)
py.iplot(table, filename='jupyter-table1')
tillahoffmann commented 3 years ago

Similar to #20, I think this is out of scope for this plugin; it is not meant to provide a full Jupyter experience but simply allow for evaluation of small code snippets. Contributions welcome, however.