So, what could be happenning here is that the initial layout doesn’t have any dash_core_components components? i.e. if we serving dash_core_components as the response of a callback then Dash might only see dash_html_components in the app.layout and so it doesn’t serve the necessary JS and CSS bundles that are required for the dash-core-components component that is rendered in the future.
@chriddyp I think that is exactly what’s happening in my case too. But I’m not sure if that should be considered a bug or I just don’t know how to solve it.
Sample App
import dash
from dash.dependencies import Input, Output
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div([
html.H2('Demo'),
# Works, if uncommented
# dcc.Input(id='input1', type='text', value='Rendered ok'),
html.Button('Show P', id='button1'),
html.Button('Show Input', id='button2'),
html.Div(id='container1'),
html.Div(id='container2'),
])
@app.callback(
Output('container1', 'children'),
[Input('button1', 'n_clicks')],
)
def on_button1_click(clicks: int):
if clicks:
return html.P('That works!')
@app.callback(
Output('container2', 'children'),
[Input('button2', 'n_clicks')],
)
def on_button2_click(clicks: int):
if clicks:
return dcc.Input(id='input2', type='text')
if __name__ == '__main__':
app.run_server(debug=True)
Problem
This app has two buttons. “Show P”, it creates some text element, “Show Input” creates core Input()
component.
Now the problem is with the Input
component. After “Show Input” is pressed, I can see JavaScript error in console log:
Error: dash_core_components was not found.
If the line in here is uncommented:
app.layout = html.Div([
html.H2('Demo'),
# Works, if uncommented
dcc.Input(id='input1', type='text', value='Rendered ok'),
html.Button('Show P', id='button1'),
html.Button('Show Input', id='button2'),
html.Div(id='container1'),
html.Div(id='container2'),
])
It works just fine. Well, because apparently dash core components library get’s loaded.
Questions
- @lewis how did you solve your problem?
- Is there an explicit way to tell Dash to load specific components? In my case Dash Core Components?
- Is this a bug? Cause I have some spare time and motivation to work on this