Hello Team,
I have to create one interacting graph which will change by selecting the Heat & pressure. Heat RadioItems is having different graph heading and X axis data & y-axis data similarly Pressure is created using other X-Y axix data.
Could you please support me to work it.
Thank you for your help.
Please find my below code
from dash import Dash, html, dcc, Input, Output, State
import pandas as pd
import plotly.express as px
measurements = pd.read_csv('dataframe.csv')
app = Dash()
app.layout = html.Div([
html.H1('Measurement Report Analysis'),
html.P(['This dashboard shows the Heat & Pressure measurement results :']),
dcc.RadioItems(id='type-radio',
options=measurements['type'].unique(),
value='Smooth'),
html.Br(),
dcc.Dropdown(id='sample_name-dropdown'),
html.Br(),
dcc.RadioItems(id='data-radio',
options={
'Heat': 'Heat measurement',
'Pressure': 'Pressure measurement'
},
value='Heat measurement'),
html.Br(),
html.Button(id='submit-button',
n_clicks=0,
children='Update the Output Graph'),
dcc.Graph(id='graph')])
@app.callback(
Output('sample_name-dropdown', 'options'),
Output('sample_name-dropdown', 'value'),
Input('type-radio', 'value'))
def update_dropdown(selected_dimple_type):
filtered_measurements = measurements[measurements['type'] == selected_dimple_type]
sample_name_options = filtered_measurements['sample_name'].unique()
return sample_name_options, sample_name_options[0]
@app.callback(
Output('graph', 'figure'),
Input('submit-button', 'n_clicks'),
Input('sample_name-dropdown', 'value'),
Input('data-radio', 'value'))
def update_graph(button_click, sample_name_options, selected_data):
filtered_measurements = measurements[measurements['sample_name'] == sample_name_options]
if selected_data =='Heat':
line_fig = px.line(filtered_measurements,
x='velocity', y='heat',
title=f'Heat measurement for {sample_name_options}')
return line_fig
elif selected_data =='Pressure':
line_fig = px.line(filtered_measurements,
x='mfr', y='pressure drop',
title=f'Pressure drop measurement for {sample_name_options}')
return line_fig
if __name__ == '__main__':
app.run_server(debug=True,use_reloader=False)