-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dash does not properly work with library called jupyter_dash [BUG] #1907
Comments
Same error here |
I'm also experiencing this error in a jupyter notebook without jupyter_dash, here's my notebook (scrubbed domain name for privacy): import dash
from dash import dcc
from dash import html
import pandas as pd
import plotly.express as px
import dash_bootstrap_components as dbc #NOTE: reload the whole app code if altering the callbacks, else the UI can bug out
app_port = 88900
#flask is default if nothing set
import flask
server = flask.Flask(__name__)
app = dash.Dash(__name__, server=server, external_stylesheets=[dbc.themes.BOOTSTRAP])
server = app.server
#Demo App
#--------
# assume you have a "long-form" data frame
# see https://plotly.com/python/px-arguments/ for more options
df = pd.DataFrame({
"Fruit": ["Apples", "Oranges", "Bananas", "Apples", "Oranges", "Bananas"],
"Amount": [4, 1, 2, 2, 4, 5],
"City": ["SF", "SF", "SF", "Montreal", "Montreal", "Montreal"]
})
fig = px.bar(df, x="Fruit", y="Amount", color="City", barmode="group")
app.layout = html.Div(children=[
html.H1(children='Hello Dash'),
html.Div(children='''
Dash: A web application framework for your data.
'''),
dcc.Graph(
id='example-graph',
figure=fig
)
]) from multiprocessing import Process
from IPython.display import IFrame
class Dash_jhub_app:
# instance attribute
def __init__(self,app):
self.app = app
def _render_app(self):
self.app.config.update({
# remove the default of '/'
'requests_pathname_prefix': f'{self.port}/'
})
self.app.run_server(port=self.port,debug=self.debug)
def start(self,port,debug=True):
self.port = port
self.debug = debug
self.thread= Process(target=self._render_app) #args=(self.app,self.port)
self.thread.start()
def url(self,user,url='https://jhub.DOMAIN.local/user/'):
self.user = user
self.url = f'{url}{self.user}/proxy/{self.port}'
print(f'visit app at: {self.url}')
def show(self,color="white" ):
return IFrame(self.url, width='100%', height='600px',allowtransparency="true",style=f"background-color: {color};" )
def stop(self):
self.thread.terminate() _app = Dash_jhub_app(app) _app.start(app_port)
_app.url(user='cogert')
! pip freeze | grep dash
_app.stop() |
Same here and the jupyter_dash lib has not seen a commit in a long time! |
We're working on a fix, but in the meantime, add this before your del app.config._read_only["requests_pathname_prefix"] Main issue: plotly/jupyter-dash#75 |
Great thanks @alexcjohnson! |
Fixed in |
Thank you for providing this fantastic library.
I had a problem dash/jupyter_dash that I copied below.
AttributeError Traceback (most recent call last)
/var/folders/xv/d091l2wd693b381xlqk8r1500000gn/T/ipykernel_5375/385882412.py in
50
51 if name == "main":
---> 52 app.run_server(mode = "external", debug=True, port=8050)
53 # app.run_server(debug=True, mode='inline',host="0.0.0.0",port=8058)
~/opt/anaconda3/envs/DPWorld2_conda_install_only/lib/python3.8/site-packages/jupyter_dash/jupyter_app.py in run_server(self, mode, width, height, inline_exceptions, **kwargs)
229 else:
230 requests_pathname_prefix = '/'
--> 231 self.config.update({'requests_pathname_prefix': requests_pathname_prefix})
232
233 # Compute server_url url
~/opt/anaconda3/envs/DPWorld2_conda_install_only/lib/python3.8/site-packages/dash/_utils.py in update(self, other)
167 # Overrides dict.update() to use setitem above
168 for k, v in other.items():
--> 169 self[k] = v
170
171 # pylint: disable=inconsistent-return-statements
~/opt/anaconda3/envs/DPWorld2_conda_install_only/lib/python3.8/site-packages/dash/_utils.py in setitem(self, key, val)
156 def setitem(self, key, val):
157 if key in self.dict.get("_read_only", {}):
--> 158 raise AttributeError(self._read_only[key], key)
159
160 final_msg = self.dict.get("_final")
AttributeError: ('Read-only: can only be set in the Dash constructor or during init_app()', 'requests_pathname_prefix')
The text was updated successfully, but these errors were encountered: