# Here goes everything that should appear in the app and the user can interact with
app_ui = ui.page_fluid(
# Add title
"Emissions Aotearoa",
# Add selection of industry to display
#ui.input_radio_buttons("industry", "Select industry", sectors),
ui.input_checkbox_group("industry_check", "industry", sectors),
ui.output_plot("emission_plot"),
# Add table
ui.output_table("emissions_table"),
)
# Here goes everything that happens in the background: data, computations, etc...
def server(input, output, session):
# Load dataset
infile = Path(__file__).parent / "emissions_data_simple.csv"
df = pd.read_csv(infile)# Define list/dictionary with possible sectors
sectors = ["Agriculture", "Households", "Road transport"]
# Here goes everything that should appear in the app and the user can interact with
app_ui = ui.page_fluid(
# Add title
"Emissions Aotearoa",
# Add selection of industry to display
ui.input_radio_buttons("industry_check", "Select industry", sectors)
)Then run the app
# Define list/dictionary with possible sectors
sectors = ["Agriculture", "Households", "Road transport"]
# Here goes everything that should appear in the app and the user can interact with
app_ui = ui.page_fluid(
# Add title
"Emissions Aotearoa",
# Add selection of industry to display
ui.input_radio_buttons("industry_check", "Select industry", sectors)
)# Define list/dictionary with possible sectors
sectors = ["Agriculture", "Households", "Road transport"]
# Here goes everything that should appear in the app and the user can interact with
app_ui = ui.page_fluid(
# Add title
"Emissions Aotearoa",
# Add selection of industry to display
ui.input_radio_buttons("industry_check", "Select industry", sectors),
# Add table
ui.output_table("emissions_table")
)Move import outside the table-creating function
# Load dataset
infile = Path(__file__).parent / "emissions_data_simple.csv"
df = pd.read_csv(infile)Create a reactive element
Create a “nameless” function to update the table
# Update the table when checkboxes are selected/unselected
@reactive.Effect
@reactive.event(input.industry_check)
def _():
# Always re-set the table to the full dataset, otherwise we break the dataframe
df_table.set(df)
new_val = df_table()[df_table()["anzsic_descriptor"] == input.industry_check()] # Use this for radio buttons
df_table.set(new_val)Create a “nameless” function to update the table
# Update the table when checkboxes are selected/unselected
@reactive.Effect
@reactive.event(input.industry_check)
def _():
# Always re-set the table to the full dataset, otherwise we break the dataframe
df_table.set(df)
new_val = df_table()[df_table()["anzsic_descriptor"] == input.industry_check()] # Use this for radio buttons
df_table.set(new_val)
# Define table
@output
@render.table
def emissions_table():
return df_table()Add the following lines to the server function
Add the following line to the UI function
# Here goes everything that should appear in the app and the user can interact with
app_ui = ui.page_fluid(
# Add title
"Emissions Aotearoa",
# Add selection of industry to display
ui.input_radio_buttons("industry_check", "Select industry", sectors),
# Add table
ui.output_table("emissions_table"),
# Add plot
ui.output_plot("emission_plot")
)Modify the UI function
# Here goes everything that should appear in the app and the user can interact with
app_ui = ui.page_fluid(
# Add title
"Emissions Aotearoa",
# Add selection of industry to display
#ui.input_radio_buttons("industry_check", "Select industry", sectors), # Use this for radio buttons
ui.input_checkbox_group("industry_check", "industry", sectors), # Use this for checkbox
ui.output_plot("emission_plot"),
# Add table
ui.output_table("emissions_table")
)Add this to the server function
def _():
# Always re-set the table to the full dataset, otherwise we break the dataframe
df_table.set(df)
#new_val = df_table()[df_table()["anzsic_descriptor"] == input.industry_check()] # Use this for radio buttons
new_val = df_table()[df_table()["anzsic_descriptor"].isin(input.industry_check())] # Use this for checkbox
df_table.set(new_val)