-
Notifications
You must be signed in to change notification settings - Fork 229
Cannot instantiate JupyterDash instance with fresh install #115
Description
As of Flask 2.3.0, the app.before_first_request
decorator has been removed. Since creating a JupyterDash
instance depends on this, this means the project as written technically has a flask<2.3.0
dependency. On a fresh install, this defaults to grabbing a Flask version past 2.3.0 and hence cannot be run.
Steps to reproduce
In a new virtual environment, install jupyter-dash
. Then in a notebook hooked up to the venv, run:
from jupyter_dash import JupyterDash
app = JupyterDash()
which results in the following error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[2], line 1
----> 1 app = JupyterDash()
File ~/qb_test/venv/lib/python3.10/site-packages/jupyter_dash/jupyter_app.py:103, in JupyterDash.__init__(self, name, server_url, **kwargs)
96 warnings.warn(
97 "The {prop} argument is ignored when running in Colab".format(
98 prop=prop
99 )
100 )
102 # Call superclass constructor
--> 103 super(JupyterDash, self).__init__(name=name, **kwargs)
105 if not JupyterDash._in_ipython:
106 # Nothing else to do when not running in a Jupyter context
107 return
File ~/qb_test/venv/lib/python3.10/site-packages/dash/dash.py:501, in Dash.__init__(self, name, server, assets_folder, pages_folder, use_pages, assets_url_path, assets_ignore, assets_external_path, eager_loading, include_assets_files, url_base_pathname, requests_pathname_prefix, routes_pathname_prefix, serve_locally, compress, meta_tags, index_string, external_scripts, external_stylesheets, suppress_callback_exceptions, prevent_initial_callbacks, show_undo_redo, extra_hot_reload_paths, plugins, title, update_title, long_callback_manager, background_callback_manager, **obsolete)
498 plugin.plug(self)
500 if self.server is not None:
--> 501 self.init_app()
503 self.logger.setLevel(logging.INFO)
File ~/qb_test/venv/lib/python3.10/site-packages/dash/dash.py:545, in Dash.init_app(self, app, **kwargs)
542 """Handle a halted callback and return an empty 204 response."""
543 return "", 204
--> 545 self.server.before_first_request(self._setup_server)
547 # add a handler for components suites errors to return 404
548 self.server.errorhandler(InvalidResourceError)(self._invalid_resources_handler)
AttributeError: 'Flask' object has no attribute 'before_first_request'
I don't know enough about the code to suggest a fix, or whether this project is still being maintained at all based on #110, but given the library cannot be used out of the box it seems like at least a small patch should be released.
Workaround
In case anyone stumbles upon this same issue and the project isn't updated any time soon, a quick workaround is to install a lower version of Flask, e.g.
pip install jupyter-dash
pip install Flask==2.2.0
This is less than ideal, since you won't be able to upgrade Flask ever, but will at least let you create a JupyterDash instance. I haven't tested if this might break anything else in the package.