2

I'm constructing a dashboard with Taipy GUI. To do so, I'm using Pandas CSV, the easiest way to import a data frame. I don't deal much with numbers, but much more with strings.

The idea is to create a form for people gathering evaluate (separate pages)

On the dashboard, we have :

  • the entities that we evaluate,
  • the date of the evaluation,
  • the 5 criteria of evaluation.

The dashboard is only showing the result for one day.

I want to make two filters :

  • The first one on the entities,
  • The second on the date. and let the dashboard update.

Could you give me or point me to some examples, please?

Afterward, I want to do so with SQLite3 files and SPARQL queries. Any examples to share with me, please? Thanks in advance.

  • you want to have examples for what exactly? How to filter on a Pandas dataframe? Also, if you want to use SPARQL on a relational database like SQLite, you'll need some OBDA engine that converts SPARQL to SQL. Ontop would be my suggestion - and in fact, this will need the creation of some mapping. Ontop tutorials are online and free – UninformedUser May 06 '23 at 08:47

1 Answers1

1

If you are using a Taipy Table, you can first put the "filter" property to True. It allows filtering the data on the different columns.

If this is enough for some reason, you can filter with some code. the code below is a simple example of code to filter dates and string.

from taipy.gui import Gui 
import pandas as pd
import datetime as dt
import numpy as np

# this function will filter the dataframe
# we can have multiple functions to filter it depending on the
# visual elements that have been changed to be more efficient
def filter_data(data, input_str, start_date, end_date):
    index = (data['Date'] >  np.datetime64(start_date)) &\
            (data['Date'] <  np.datetime64(end_date)) &\
            (data["Value"].apply(lambda x: input_str in x))
    
    filtered_data = data[index]
    return filtered_data

# processing of a DataFrame (two columns: Date, Value)
original_data = pd.read_csv("graph_examples/airline_passengers.csv")
original_data['Date'] = pd.to_datetime(original_data['Date']) 
original_data['Value'] = original_data['Value'].astype(str)

# Initialization of variables of the GUI
input_for_filter = ""

start_date = dt.datetime(1950,1,1)
end_date = dt.datetime(1960,1,1)

filtered_data = filter_data(original_data,
                            input_for_filter,
                            start_date,
                            end_date)

# simple Markdown
md = """
<|{input_for_filter}|input|on_change=on_changer_filter|>

<|{start_date}|date|on_change=on_changer_filter|> <|{end_date}|date|on_change=on_changer_filter|>

<|{filtered_data}|table|>
"""

# function called by the GUI to filter the dataframe when a change is being done
# on visual elements
def on_changer_filter(state):
    state.filtered_data = filter_data(original_data,
                                      state.input_for_filter,
                                      state.start_date,
                                      state.end_date)
    
# GUI running
Gui(md).run()

I hope this will help you to create your own filtering.

Florian Jacta
  • 1,143
  • 1
  • 2
  • 5