GibbsConsulting / jupyter-plotly-dash

Jupyter notebook wrapper for plotly dash applications
GNU Affero General Public License v3.0
81 stars 12 forks source link

issue with state #59

Closed george-codes closed 4 years ago

george-codes commented 4 years ago

I had an existing app with a callback include State, but now seems to throw an error regarding "not defined". Here is a simple example that demonstrates the error:

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from jupyter_plotly_dash import JupyterDash

app = JupyterDash('InteractivePyDEFDemotest')

app.layout = html.Div([
    dcc.Input(id='input-1-state', type='text', value='Montréal'),
    dcc.Input(id='input-2-state', type='text', value='Canada'),
    html.Button(id='submit-button-state', n_clicks=0, children='Submit'),
    html.Div(id='output-state')
])
@app.callback(Output('output-state', 'children'),
              [Input('submit-button-state', 'n_clicks')],
              [State('input-1-state', 'value'),
               State('input-2-state', 'value')])
def update_output(n_clicks, input1, input2):
    return u'''
        The Button has been pressed {} times,
        Input 1 is "{}",
        and Input 2 is "{}"
    '''.format(n_clicks, input1, input2)

Traceback (most recent call last):
  File "/anaconda/anaconda3/lib/python3.7/site-packages/ipykernel/comm/manager.py", line 111, in comm_msg
    comm.handle_msg(msg)
  File "/anaconda/anaconda3/lib/python3.7/site-packages/ipykernel/comm/comm.py", line 159, in handle_msg
    self._msg_callback(msg)
  File "/anaconda/anaconda3/lib/python3.7/site-packages/jupyter_plotly_dash/nbkernel.py", line 47, in callback
    response, mimetype = app.process_view(stem, args, app_path)
  File "/anaconda/anaconda3/lib/python3.7/site-packages/jupyter_plotly_dash/dash_wrapper.py", line 152, in process_view
    resp, rmt = func(args, app_path, view_name_parts)
  File "/anaconda/anaconda3/lib/python3.7/site-packages/jupyter_plotly_dash/dash_wrapper.py", line 183, in rv__dash_update_component
    resp = mFunc()
  File "/anaconda/anaconda3/lib/python3.7/site-packages/django_plotly_dash/dash_wrapper.py", line 560, in dispatch
    return self.dispatch_with_args(body, argMap=dict())
  File "/anaconda/anaconda3/lib/python3.7/site-packages/django_plotly_dash/dash_wrapper.py", line 629, in dispatch_with_args
    for c in state:
NameError: name 'state' is not defined

My dash version is 1.11 My jpyter-plotly-dash version is 0.4.0

If I can narrow down the issue even more, I will post back. thanks!

GibbsConsulting commented 4 years ago

Can you try upgrading to the most recent version of django-plotly-dash? That should address this issue

george-codes commented 4 years ago

Thanks, that did the trick! All set and back to normal :)