plotly / jupyter-dash

OBSOLETE - Dash v2.11+ has Jupyter support built in!
https://dash.plotly.com/dash-in-jupyter
MIT License
955 stars 234 forks source link

I would like to know if there is a way to refresh the jupyter dash server without restarting the kernel #99

Open mumususu opened 2 years ago

mumususu commented 2 years ago

I am using jupyter dash to make a dash project on a jupyter notebook. Every time I update my code, I have to kill the kernel and then restart the jupyter notebook to get the changed code to work properly. Otherwise, the dash page will show a double loading error. I would like to know if there is a way to refresh the jupyter dash server without restarting the kernel.

jon-abbott commented 2 years ago

Here is an unofficial workaround that seems to work for refreshing callback cells without restarting the kernel:

  1. Close any running Jupyter Notebook or JupyterLab instances
  2. Make a backup of the file ~/anaconda3/lib/python3.9/site-packages/jupyter_dash/jupyter_app.py (note: the path may differ depending on your system type and installation location of jupyter-dash)
  3. Open the original jupyter_app.py in a text editor
  4. Change the line: kwargs['dev_tools_hot_reload'] = mode == "external" to be kwargs['dev_tools_hot_reload'] = True and then save and close the file
  5. Reopen Jupyter Notebook or JupyterLab as usual

This uses the hot reload capability of Dash to allow you to edit and run Jupyter cells and then see the changes for any newly-drawn callbacks. Any HTML that is already rendered won't change, however. Perhaps the dash or jupyter-dash authors know of a way to safely refresh all rendered objects?

Also, note that jupyter_app.py mentions that enabling the code change above can sometimes cause Jupyter problems when there is no active kernel. I haven't encountered this issue yet.

benedikt-budig commented 1 year ago

this might also be solved by https://github.com/plotly/jupyter-dash/pull/105