Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Cannot instantiate JupyterDash instance with fresh install #115

Closed
rickymagner opened this issue May 24, 2023 · 3 comments
Closed

Cannot instantiate JupyterDash instance with fresh install #115

rickymagner opened this issue May 24, 2023 · 3 comments

Comments

@rickymagner
Copy link

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.

@alexcjohnson
Copy link
Collaborator

FYI two things:

  1. We're about to place an upper limit on the Flask version installed with dash because of repeated issues like this Upper bound on Flask and Werkzeug versions dash#2538
  2. This entire package is about to be obsolete, when we merge its functionality into the main dash package Merge JupyterDash with Dash dash#2530

@alexcjohnson
Copy link
Collaborator

That said, I think you have an old version of Dash installed (check dash.__version__) - in plotly/dash#2265 (part of Dash v2.7.0) we removed that before_first request call.

@rickymagner
Copy link
Author

Those are all great to hear, especially that this project will get merged into the main Dash package. You're right, I had a slightly older version of Dash as well, so upgrading that should do the trick too. Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants