{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Directory format for bokeh apps and templates\n", "\n", "Bokeh apps can also be defined with a directory format. This format allows the use of additional modules, data, templates, themes and other functions. The directory should contain a main.py file, which is the entry point for the app, but other parts can be included:\n", "\n", "```\n", ".\n", "└── myapp\n", " ├── __init__.py\n", " ├── main.py\n", "    ├── request_handler.py\n", "    ├── static\n", " │ └── css\n", " │ └── custom.min.css\n", "    ├── templates\n", "    │   └── index.html\n", "    └── theme.yaml\n", "```\n", "\n", "* `__init__.py`\n", "\n", " initiates this package.\n", "\n", " Imports relative to the package can also be made there, for example `from . import mymod` and `from .mymod import func`.\n", "\n", "* `request_handler.py`\n", "\n", " for optional functions, for example, to process HTTP requests and return a dict containing a session token, as described in [Request handler hooks](https://docs.bokeh.org/en/2.4.0/docs/user_guide/server.html#userguide-server-request-handler).\n", "\n", "* `app_hooks.py`\n", "\n", " for optional callbacks that can be triggered in different phases of execution, as described in [Lifecycle hooks](https://docs.bokeh.org/en/2.4.0/docs/user_guide/server.html#userguide-server-applications-hooks).\n", "\n", "* `static`\n", "\n", " Subdirectory for static resources of this application.\n", "\n", "* `theme.yaml`\n", "\n", " for declaring standard attributes that Bokeh should apply to model types.\n", "\n", "* `templates`\n", "\n", " Subdirectory with a Jinja template `index.html`. The directory can contain further Jinja templates to which `index.html` refers.\n", " \n", " Further information can be found at [Customizing the application’s Jinja template](https://docs.bokeh.org/en/2.4.0/docs/user_guide/server.html#userguide-server-template).\n", "\n", "You can find a complete example at: https://github.com/bokeh/bokeh/tree/branch-3.3/examples/server/app/dash. After you have downloaded the `dash` folder, you can start the Bokeh server with\n", "\n", "``` bash\n", "$ pipenv run python -m bokeh serve --show dash/\n", "\n", "$ pipenv run python -m bokeh serve --show examples/app/dash/\n", "2019-02-08 19:02:42,829 Starting Bokeh server version 1.0.4 (running on Tornado 5.1.1)\n", "2019-02-08 19:02:42,835 Bokeh app running at: http://localhost:5006/dash\n", "```\n", "![Bokeh dashboard](bokeh-dashboard.png)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.11 Kernel", "language": "python", "name": "python311" }, "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.11.4" }, "latex_envs": { "LaTeX_envs_menu_present": true, "autoclose": false, "autocomplete": true, "bibliofile": "biblio.bib", "cite_by": "apalike", "current_citInitial": 1, "eqLabelWithNumbers": true, "eqNumInitial": 1, "hotkeys": { "equation": "Ctrl-E", "itemize": "Ctrl-I" }, "labels_anchors": false, "latex_user_defs": false, "report_style_numbering": false, "user_envs_cfg": false }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }