@msuths1 wrote:
Hi,
Is using dropdowns with px.histogram possible? I wrote some code using the same format as I have for previous px. plots yet I get an error stating KeyError: None.
Any help would be appreciated.import dash import dash_core_components as dcc import dash_html_components as html import flask import plotly.express as px from dash.dependencies import Input, Output import pandas as pd server = flask.Flask(__name__) app = dash.Dash(__name__, server=server) df = pd.read_csv('/Users/mythilisutharson/documents/cam_work/mof_explorer_flourish/MOF_trans_data2.csv') features = df.columns app.layout = html.Div([ html.Div([dcc.Graph(id='dist-plot', animate=False)]), html.Div([ html.Label(["Select X variable:", dcc.Dropdown(id='xaxis-dist', options=[{'label': i, 'value': i} for i in features], multi=False, placeholder="Select an option for X" )]), ]) ]) @app.callback(Output("dist-plot", "figure"), [Input('xaxis-dist', "value"), ]) def make_figure(x): return px.histogram(df, x=df[x], marginal="rug", color="MOF family", animation_frame="Pressure (bar)", hover_data=df.columns, hover_name="DDEC code", ).update_xaxes(showgrid=False, title="Density", autorange=True ).update_yaxes(title=' ', showgrid=False, autorange=True).update_layout( clickmode='event+select', hovermode='closest', margin={'l': 50, 'b': 80, 't': 50, 'r': 10}, autosize=True ).update_traces(marker=dict(opacity=0.7, line=dict(width=0.5, color='DarkSlateGrey'), )) app.run_server(debug=True)The data used is the following:
Thank you!
Posts: 3
Participants: 2