An Simple Interactive Dashboard with Callbacks:
- Write the import statements:
python
1from dash import Dash, html, dcc, jupyter_dash, Input, Output
2import pandas as pd
3import plotly.express as px- Initialize the Dash app:
python
1app = Dash(__name__)- Define the layout of the app:
- The layout of a Dash app is defined using a Div component to contain an Input component and an H1 component.
python
1app.layout = html.Div([
2 dcc.Input(
3 id='input-text',
4 type='text',
5 value='Change this default text'),
6 html.H1(
7 id='output-text',
8 children='',
9 )
10])- Define the callback function to update the output text based on the input text:
- The function’s input parameter, input_text, will get its value based on the input object in the callback decorator. In this case, it will get the value of the input text box with id input-text.
python
1@app.callback(
2 Output(component_id='output-text', component_property='children'),
3 Input(component_id='input-text', component_property='value')
4)
5def update_output_header(input_text):
6 return f'You entered: {input_text}'- Run the app:
python
1if __name__ == '__main__':
2 app.run(debug=True)