plotly / dash

Data Apps & Dashboards for Python. No JavaScript Required.
https://plotly.com/dash
MIT License
21.53k stars 2.07k forks source link

Better documentation for using with Binder/JupyterHub #1057

Open tdpetrou opened 4 years ago

tdpetrou commented 4 years ago

I write tutorials and do lots of live teaching and gravitate mostly to using Jupyter Notebooks, which allow for text and code to be integrated together in one. Using dash on a local instance of Jupyter is essentially no different than using it from a normal .py file.

But, when teaching to people that have no local jupyter instance or don't even have python installed, I've turned to Binder which relies on JupyterHub.

It took some searching, but I found some github issues and forum posts that informed me I had to set requests_pathname_prefix of the config dictionary like this.

port = 9999
base_prefix = '{}proxy/{}/'.format(os.environ['JUPYTERHUB_SERVICE_PREFIX'], port)
url = 'https://hub.gke.mybinder.org{}'.format(base_prefix)
app.config.update({'requests_pathname_prefix': base_prefix})
app = dash.Dash()
app.run_server(host='0.0.0.0', port=port)

Would be great if this was officially documented somewhere. Thanks and this is a great product. I'm doing a meetup on it in Houston on Jan 2 (apologies if this is self promotion, so no link provided).

audetto commented 4 years ago

Fantastic. Been trying for hours to find the right combination of flags to make this work.

This is really worth documenting.

But, I wanted to ask about a "more elegant" solution, something I have seen working in r shiny.

The above solution will make the app work via the Reverse Proxy, but not natively (where the extra prefix breaks the links).

If Dash links were relative to the location of the first page, then the same app could work in both cases (or via multiple proxies). I am sure there must be a good reason why the links in the html are absolute and not relative and I have no idea what is the tradeoff, but worth adding this to the doc as well.

audetto commented 4 years ago

Now that I know, I can find examples and some sort of documentation

https://github.com/plotly/dash-recipes/blob/master/dash-routes-config.py https://github.com/plotly/dash/issues/179