We use sqlalchemy to access the database. It is going to call the psycopg2 library we installed in the previous part.

The same libraries for visualization and data analysis are called as in the previous example. Note DatetimeTickFormatter is necessary to modify the aspect of dates, otherwise they'll be not readable (and this without counting on the default unsorted American -- rather than ISO -- format).

We first set the database authentication variables, then we can create the PostgreSQL engine.

Then we can use an SQLAlchemy trick to load all available tables. With Node-Red, we create all tables within the th schema, and each table has the same features. We can fetch them all as follows:

As for the live example, we check first only the office "bureau":

We can filter e.g. between today and three days ago:

We can inject the SQL response directly into the pandas Dataframe instanciator:

Formatting the dates in the French format:

Alright, everything works as expected!

We now design a more complex dashboard. It should be able to:

A param class can be interpreted by Panel. This type of class lets us define each parameter with their types, limits, names, and whatnots. Then Panel will be able to automatically interpret these parameters to generate the appropriate widgets.

We can then make methods that return a type which can be visualized within a Panel Pane, e.g. a Holoviews plot.

Here is the doc: https://panel.holoviz.org/user_guide/Param.html

We instanciate

We can now lay out the various widgets and methods returning viewable objects. We're going to use some of the Layout objects of Panel: rows and columns, but also tabs.

First, let's see how widgets for the parameters are generated and how to lay them out the way we want. We can simply call the param element of our instance mypanel inside a pn.Param layout:

We can now put one of the method inside a layout:

Note that even if the widgets are in a separate cell, the plot will update if you change the parameters. It is interactive! There is a single upper_date parameter for my mypanel instance. You can return the widgets as many times you want: it is actually the same object so they all update! You can try:

Now we build our entire dashboard, with both plots, each in one tab, and their associated widgets/parameters:

Here's our dashboard!

There are certainly many points to improve, in particular fetching data everytime the dates are changed. If the new data set is already inside the previous one, we shouldn't need to do that.