Currently learning to develop dashboard application with Shiny for Python, I am facing issues while trying to plot a graph with filtered data.
I am using an initial dataset, I want to filter using patient name or date I collect from data range selector or select box. To perform the data selection, I tried to setup a reactive function that make the row selection using pandas library.
When I want to display the graph (count plot for example), I receive the following message
min() arg is an empty sequence
I don't see this error if I directly plot the graph with non filtered data.
So I guess there is something wrong during the filtering step:
from shiny.express import input, render, ui
from shiny import reactive
import plotly.express as px
import pandas as pd
import numpy as np
import seaborn as sns
from shinywidgets import reactive_read, render_widget
df_patient = pd.read_excel(r"C:\Users\rdesb\OneDrive\Bureau\MyAPP\dashboard\db_patient.xlsx",
index_col="Indice")
df_ABS = pd.read_excel(r"C:\Users\rdesb\OneDrive\Bureau\MyAPP\dashboard\Bdd_ABS.xlsx")
liste_patient = pd.unique(df_ABS["Patient"])
liste_patient = tuple(liste_patient)
#df_patient["Date de naissance"] = pd.to_datetime(df_patient["Date de naissance"], format='%d-%m-%Y')
#INTERFACE GRAPHIQUE
ui.page_opts(title="DashBoard Plume", fillable=True)
with ui.nav_panel("Informations Patients"):
ui.h2("Informations Patients")
@render.data_frame
def patients_df():
return render.DataGrid(df_patient)
with ui.nav_panel("Statistiques"):
with ui.layout_columns():
with ui.card(full_screen=False, height=100):
ui.card_header("Selection de date")
ui.input_date_range("daterange", "Date range", start="2020-01-01")
with ui.card(full_screen=False, height=100):
ui.card_header("Selection patient")
ui.input_select(
"patient_select",
"Choisissez un patient:",
liste_patient, )
@reactive.Calc
def df_ABS_sorted():
return df_ABS.loc[df_ABS["Patient"]== {input.patient_select()}]
with ui.layout_columns():
with ui.card(full_screen=False, height=700):
@render.plot(alt="Affichage données triées par patient et date")
def plot():
ax = sns.countplot(data=df_ABS_sorted(), x="Patient")
ax.set_title("Absences")
ax.set_xlabel("Nom")
ax.set_ylabel("Counts")
return ax
@render.text
def value():
return f"{input.patient_select()}"

I also tried not using reactive calculation and directly type the "filtered" conditions, that lead to the same error.
I guess there is something wrong typing directly
df_ABS.loc[df_ABS["Patient"]== {input.patient_select()}]
maybe something conflcit with the type?