The jupyter-dash
package makes it easy to develop Plotly Dash apps from the Jupyter Notebook and JupyterLab.
Just replace the standard dash.Dash
class with the jupyter_dash.JupyterDash
subclass.
!pwd
import os
pkg_root_dir = !pwd
pkg_root_dir=pkg_root_dir[0]
os.environ["GRID2VIZ_ROOT"] = pkg_root_dir
config_path = os.path.join(pkg_root_dir, "config.ini")
Writing the config-file to launch the app
CONFIG_FILE_CONTENT = """
# This file have been automatically generated, please do not modify it.
# You can remove it once done with the application.
[DEFAULT]
agents_dir={agents_dir}
env_dir={env_dir}
n_cores={n_cores}
# This file will be re generated to each call of "python -m grid2viz.main"
"""
#short demo
#agents_dir = os.path.join(pkg_root_dir,"grid2viz", "data", "agents")
#complete demo over some "warm-up" scenarios of NeurIPS robustness track competition
agents_dir = os.path.join(pkg_root_dir,"Grid2viz-dataset", "NeurIPS_1.2.2_week1")
env_dir = os.path.join(pkg_root_dir,"grid2viz", "data", "env_conf")
n_cores = 2#args.n_cores
with open(config_path, "w") as f:
f.write(CONFIG_FILE_CONTENT.format(agents_dir=agents_dir,
env_dir=env_dir,
n_cores=n_cores))
The documentation of the Grid2viz application can be found here: https://grid2viz.readthedocs.io/en/latest/
#!pip install jupyter-dash
NOTE:
We run the following code twice
to actually see the application runnning and get the url where to load the app
#Run it twice sometimes to actually see it runnning and getting the url to go to paly the app
from grid2viz.app_jupyter import app as app_jup
app_jup.run_server()#mode="inline",debug=True)
app_jup.run_server() #you should get the app url as the output of the cell
#if you want to run it in the notebook
#app_jup.run_server(port=8052,mode="inline")#mode="inline",debug=True)
When running in JupyterLab, with the jupyterlab-dash
extension, setting mode="jupyterlab"
will open the app in a tab in JupyterLab.
app.run_server(mode="jupyterlab")