Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught ReferenceError: Plotly is not defined #46

Open
irisvanheck opened this issue Jun 27, 2024 · 12 comments
Open

Uncaught ReferenceError: Plotly is not defined #46

irisvanheck opened this issue Jun 27, 2024 · 12 comments
Assignees
Labels
bug Something isn't working

Comments

@irisvanheck
Copy link

irisvanheck commented Jun 27, 2024

Hi! While trying to use gurobi-logtools, I am encoutering the following error:

Uncaught ReferenceError: Plotly is not defined.

This is the code I'm executing in databricks:

%pip install gurobi_logtools

import gurobi_logtools as glt
import pandas as pd

results = glt.parse(["gurobi_log.log"])
summary = results.summary()
nodelog = results.progress("nodelog")

glt.plot(summary, type="box")
glt.plot(nodelog, y="Gap", color="Log", type="line")
glt.plot(results.progress("norel"), x="Time", y="Incumbent", color="Log", type="line")

I already tried to reinstall plotly and import plotly, but this does not solve the problem. Do you have any idea what could help? Thanks!

@mattmilten
Copy link
Member

mattmilten commented Jun 27, 2024

Can you please try running this small example to check whether Plotly works as intended?

import plotly.express as px
fig = px.scatter(x=[0, 1, 2, 3, 4], y=[0, 1, 4, 9, 16])
fig.show()

@mattmilten mattmilten self-assigned this Jun 27, 2024
@irisvanheck
Copy link
Author

Yes, this works fine!

@mattmilten
Copy link
Member

Huh, that's strange. Can you successfully parse your log files? You can just print the pandas DataFrame or call summary.head() to check whether it contains reasonable data.
I can only assume that something's not quite right with the ipywidget code that takes care of the interactive data selection for the visualization. You can also skip that step and call the plotly drawing methods directly, e.g.,

px.line(nodelog, x="Time", y="Gap", color="Log")

@irisvanheck
Copy link
Author

Thanks! Calling the plotly drawing method directly works :)

@mattmilten
Copy link
Member

OK, thanks for confirming that! I will try to reproduce the error on Databricks myself, and hopefully, I can figure out what is going wrong there.

@mattmilten mattmilten added the bug Something isn't working label Jun 28, 2024
@venaturum
Copy link
Member

Hi @irisvanheck can you show us the output of the following?

%pip install gurobi_logtools
%pip list

@irisvanheck
Copy link
Author

Package Version


anyio 3.5.0
argon2-cffi 21.3.0
argon2-cffi-bindings 21.2.0
asttokens 2.0.5
astunparse 1.6.3
attrs 22.1.0
backcall 0.2.0
beautifulsoup4 4.11.1
black 22.6.0
bleach 4.1.0
blinker 1.4
boto3 1.24.28
botocore 1.27.96
cachetools 5.3.2
certifi 2022.12.7
cffi 1.15.1
chardet 4.0.0
charset-normalizer 2.0.4
click 8.0.4
comm 0.1.2
contourpy 1.0.5
cryptography 39.0.1
cycler 0.11.0
Cython 0.29.32
databricks-connect 14.3.2
databricks-sdk 0.20.0
dbus-python 1.2.18
debugpy 1.6.7
decorator 5.1.1
defusedxml 0.7.1
distlib 0.3.8
distro 1.7.0
distro-info 1.1+ubuntu0.2
docstring-to-markdown 0.11
entrypoints 0.4
executing 0.8.3
facets-overview 1.1.1
fastjsonschema 2.19.1
filelock 3.14.0
fonttools 4.25.0
google-auth 2.28.1
googleapis-common-protos 1.62.0
grpcio 1.62.0
grpcio-status 1.62.0
gurobi-logtools 3.0.0
httplib2 0.20.2
idna 3.4
importlib-metadata 4.6.4
ipyflow-core 0.0.198
ipykernel 6.25.0
ipython 8.14.0
ipython-genutils 0.2.0
ipywidgets 7.7.2
jedi 0.18.1
jeepney 0.7.1
Jinja2 3.1.2
jmespath 0.10.0
joblib 1.2.0
jsonschema 4.17.3
jupyter-client 7.3.4
jupyter_core 5.2.0
jupyter-server 1.23.4
jupyterlab-pygments 0.1.2
jupyterlab-widgets 1.0.0
keyring 23.5.0
kiwisolver 1.4.4
launchpadlib 1.10.16
lazr.restfulclient 0.14.4
lazr.uri 1.0.6
lxml 4.9.1
MarkupSafe 2.1.1
matplotlib 3.7.0
matplotlib-inline 0.1.6
mccabe 0.7.0
mistune 0.8.4
more-itertools 8.10.0
mypy-extensions 0.4.3
nbclassic 0.5.2
nbclient 0.5.13
nbconvert 6.5.4
nbformat 5.7.0
nest-asyncio 1.5.6
nodeenv 1.8.0
notebook 6.5.2
notebook_shim 0.2.2
numpy 1.23.5
oauthlib 3.2.0
packaging 23.2
pandas 1.5.3
pandocfilters 1.5.0
parso 0.8.3
pathspec 0.10.3
patsy 0.5.3
pexpect 4.8.0
pickleshare 0.7.5
Pillow 9.4.0
pip 22.3.1
platformdirs 2.5.2
plotly 5.9.0
pluggy 1.0.0
prometheus-client 0.14.1
prompt-toolkit 3.0.36
protobuf 4.25.3
psutil 5.9.0
psycopg2 2.9.3
ptyprocess 0.7.0
pure-eval 0.2.2
py4j 0.10.9.7
pyarrow 8.0.0
pyarrow-hotfix 0.5
pyasn1 0.5.1
pyasn1-modules 0.3.0
pyccolo 0.0.52
pycparser 2.21
pydantic 1.10.6
pyflakes 3.1.0
Pygments 2.11.2
PyGObject 3.42.1
PyJWT 2.3.0
pyodbc 4.0.32
pyparsing 3.0.9
pyright 1.1.294
pyrsistent 0.18.0
python-apt 2.4.0+ubuntu3
python-dateutil 2.8.2
python-lsp-jsonrpc 1.1.1
python-lsp-server 1.8.0
pytoolconfig 1.2.5
pytz 2022.7
pyzmq 23.2.0
requests 2.28.1
rope 1.7.0
rsa 4.9
s3transfer 0.6.2
scikit-learn 1.1.1
scipy 1.10.0
seaborn 0.12.2
SecretStorage 3.3.1
Send2Trash 1.8.0
setuptools 65.6.3
six 1.16.0
sniffio 1.2.0
soupsieve 2.3.2.post1
ssh-import-id 5.11
stack-data 0.2.0
statsmodels 0.13.5
tenacity 8.1.0
terminado 0.17.1
threadpoolctl 2.2.0
tinycss2 1.2.1
tokenize-rt 4.2.1
tomli 2.0.1
tornado 6.1
traitlets 5.7.1
typing_extensions 4.4.0
ujson 5.4.0
unattended-upgrades 0.1
urllib3 1.26.14
virtualenv 20.16.7
wadllib 1.3.6
wcwidth 0.2.5
webencodings 0.5.1
websocket-client 0.58.0
whatthepatch 1.0.2
wheel 0.38.4
widgetsnbextension 3.6.1
XlsxWriter 3.2.0
yapf 0.33.0
zipp 1.0.0

@venaturum
Copy link
Member

If you run

%pip install plotly
import plotly.express

in the first cell of the notebook, then proceed with your code in the next cell, do you still get the error?

@irisvanheck
Copy link
Author

Unfortunately, yes: 'Uncaught ReferenceError: Plotly is not defined'

@venaturum
Copy link
Member

Based on similar error threads I found around the internet I think the issue is related to the ipywidgets which are being attached to the plotly graph, and is not specific to gurobi (but let's see if we can find a way to workaround it).

I haven't been able to reproduce your exact error on Databricks, however I don't get a satisfactory result either with the output containing "Loading widget. This should take less than 30 seconds." and not progressing.

@venaturum
Copy link
Member

There's some databricks docs on Plotly:
https://docs.databricks.com/en/visualizations/plotly.html

On the first line it says "Databricks supports Plotly 2.0.7" .... v2.0.7 was published 6 years ago. Surely this is just a case of lazy documentation.

It mentions:

To display a Plotly plot:

Specify output_type='div' as an argument to the Plotly plot() function.

Pass the output of the plot() function to Databricks displayHTML() function.

Any plotly keywords arguments can be passed through the via the gurobi_logtools plot function, however the underlying plot, which is needed for displayHTML, is not returned and it's not clear to me, when using ipywidgets in the manner that we are, that it can be.

Are you familiar with matplotlib? That might be the quickest resolution - I've been using gurobi_logtools for 1.5 years now and have never bothered with plotly, and just used matplotlib/seaborn.

@venaturum
Copy link
Member

venaturum commented Jul 1, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants