{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Grid2Viz demo using Jupyter Dash\n", "Through this notebook you will be able to launch the Grid2Viz app.\n", "\n", "Visiting next the resulting url that is shown will allow you to play with the app in your browser\n", "\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Jupyter Dash\n", "The `jupyter-dash` package makes it easy to develop Plotly Dash apps from the Jupyter Notebook and JupyterLab.\n", "\n", "Just replace the standard `dash.Dash` class with the `jupyter_dash.JupyterDash` subclass." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Tip: Get back to your home repository\n", "Click on the jupyter logo on the top left" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Configuration" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "pkg_root_dir = !pwd\n", "pkg_root_dir=pkg_root_dir[0]\n", "pkg_root_dir" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Choose Dataset to explore with grid2viz" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#short demo\n", "#dataset_agent_log_path = os.path.join(pkg_root_dir,\"grid2viz\", \"data\", \"agents\")\n", "\n", "#complete demo over some \"warm-up\" scenarios of NeurIPS robustness track competition\n", "#dataset_agent_log_path=os.path.join(pkg_root_dir,\"Grid2viz-dataset\", \"NeurIPS_1.2.2_week1\")\n", "\n", "#Best demo over some \"test\" scenarios of NeurIPS robustness track competition\n", "dataset_agent_log_path=os.path.join(pkg_root_dir,\"Grid2viz-dataset-NeurIPS-Robustness\", \"res_agents\")\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Generating necessary config for grid2viz" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "\n", "def create_config(dataset_agent_log_path):\n", " \n", "\n", " os.environ[\"GRID2VIZ_ROOT\"] = pkg_root_dir\n", "\n", " config_path = os.path.join(pkg_root_dir, \"config.ini\")\n", " \n", " CONFIG_FILE_CONTENT = \"\"\"\n", " # This file have been automatically generated, please do not modify it. \n", " # You can remove it once done with the application.\n", " [DEFAULT]\n", " agents_dir={agents_dir}\n", " env_dir={env_dir}\n", " n_cores={n_cores}\n", " # This file will be re generated to each call of \"python -m grid2viz.main\"\n", " \"\"\"\n", "\n", "\n", " #complete demo over some \"warm-up\" scenarios of NeurIPS robustness track competition\n", " agents_dir = dataset_agent_log_path#os.path.join(pkg_root_dir,\"Grid2viz-dataset\", \"NeurIPS_1.2.2_week1\")\n", "\n", "\n", " env_dir = os.path.join(pkg_root_dir,\"grid2viz\", \"data\", \"env_conf\")\n", "\n", "\n", " n_cores = 2#args.n_cores\n", "\n", " with open(config_path, \"w\") as f:\n", " f.write(CONFIG_FILE_CONTENT.format(agents_dir=agents_dir,\n", " env_dir=env_dir,\n", " n_cores=n_cores))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Writing the config-file to launch the app" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "create_config(dataset_agent_log_path)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Launching Grid2viz\n", "The **documentation** of the Grid2viz application can be found here: https://grid2viz.readthedocs.io/en/latest/" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#!pip install jupyter-dash" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**NOTE**:\n", "We run the following code `twice` to actually see the application runnning and get the url where to load the app" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#Run it twice sometimes to actually see it runnning and getting the url to go to paly the app\n", "from grid2viz.app_jupyter import app as app_jup\n", "app_jup.run_server()#mode=\"inline\",debug=True)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "app_jup.run_server() #you should get the app url as the output of the cell" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#if you want to run it in the notebook\n", "#app_jup.run_server(port=8052,mode=\"inline\")#mode=\"inline\",debug=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "When running in JupyterLab, with the `jupyterlab-dash` extension, setting `mode=\"jupyterlab\"` will open the app in a tab in JupyterLab.\n", "\n", "```python\n", "app.run_server(mode=\"jupyterlab\")\n", "```" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "formats": "ipynb,py:percent" }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.10" } }, "nbformat": 4, "nbformat_minor": 4 }