I have a data frame which I have 4 columns “Location, Sample_Date, SRB, APB” I’ve made the “Location” the index. And within this DF there could be multiple instances of a “Location”.
I’ve started creating my first Dash app and I have a dropdown and a graph.
I would like the dropdown to show only uniques values of “Location”.
Once chosen, I want it to show Each instances of that Location SRB and APB
X - Axis: each “Sample_ Dates”
Y- Axis: each value of “SRB” and “APB” for the corresponding “Sample_Dates”
Showing multiple sets of Bar graphs for each instance.
from gc import callbacks
from itertools import groupby
from dash import Dash, html, dcc, Input,Output
import plotly.express as px
import pandas as pd
import numpy as np
## data sources to be used for this project
bacteria = pd.read_excel("data/Bacteria_Firebird_ALL_2_6_2022.xlsx")
## cleaning DataFrame
bacteria = bacteria[['Location','SRB','APB','Sample Date', 'Cellular (pg per mL)']].copy()
bacteria.set_index('Location')
bacteria.sort_values(by="Sample Date")
# Initiation of Dash App
app = Dash(__name__)
app.layout = html.Div(style={'backgroundColor':colors['background']},
children=[
html.H1(
children="Well Site Inspection",
style={
'textAlign':'center',
'color':colors['text']
,'padding':5
}
),
html.H4(
children="Analyzed report for a well pull, including historic data colleted for the well.",
style={
'textAlign':'center',
'color':'#000000'
}
),
dcc.Markdown(successful_Bacteria_Program,style={'color':colors["text"],'textAlign':'center'}),
dcc.Dropdown(
bacteria['Location'].unique(),
id="dropdown",
clearable=True,
placeholder= "Please select a location.."
),
dcc.Graph(
id="Bacteria",
),
dcc.Markdown(srb_apb_MD , style={'color':colors["text"],'padding':20}),
])
@app.callback(
Output("Bacteria", "figure"),
Input("dropdown", "value")
)
def updateDashboard(my_dropdown):
df_bacteria = bacteria[bacteria['Location'] == my_dropdown]
print(df_bacteria)
bar_chart = px.bar(
data_frame=df_bacteria,
x = df_bacteria["Location"],
y = ["SRB","APB"],
title="Bacteria Sampling",
barmode='group'
)
return bar_chart