app = dash.Dash(
requests_pathname_prefix=f'/user/{os.environ.get("JUPYTERHUB_USER")}/proxy/{DASH_PORT}/',
external_stylesheets=[dbc.themes.BOOTSTRAP],
meta_tags=[
{"name": "viewport", "content": "width=device-width, initial-scale=1.0"}
],
)
app.layout = html.Div(
[
html.H1("Multi output example"),
dcc.Dropdown(
id="data-dropdown",
options=[
{"label": "Movies", "value": "movies"},
{"label": "Series", "value": "series"},
],
value="movies",
),
html.Div(
[
dcc.Graph(id="graph"),
dt.DataTable(
id="data-table",
columns=[
{"name": "Title", "id": "title"},
{"name": "Score", "id": "score"},
],
),
]
),
],
id="container",
)
@app.callback(
[
Output("graph", "figure"),
Output("data-table", "data"),
Output("data-table", "columns"),
Output("container", "style"),
],
[Input("data-dropdown", "value")],
)
def multi_outputs(value):
if value is None:
raise PreventUpdate
selected = sample_data[value]
data = selected["data"]
columns = [{"name": k.capitalize(), "id": k} for k in data[0].keys()]
figure = go.Figure(
data=[go.Bar(x=[x["score"]], text=x["title"], name=x["title"]) for x in data]
)
return figure, data, columns, selected["style"]