Construct a Information Dashboard Prototype with Generative AI | by Jo Stichbury | Jan, 2025

A ebook studying information visualization with Vizro-AI

10 min learn

14 hours in the past

This text is a tutorial that reveals tips on how to construct an information dashboard to visualise ebook studying information taken from goodreads.com. It makes use of a low-code method to prototype the dashboard utilizing pure language prompts to an open supply software, which generates Plotly charts that may be added to a template dashboard.

Discover ways to chart Goodreads studying information with this tutorial (Picture designed by FreePik)

You’ll see tips on how to iterate prompts to construct three charts then add the prompts to a Pocket book to generate an interactive dashboard. Lastly, the generated dashboard code is added to a shared venture that may be tweaked to enhance the prototype. It’s nonetheless not full and might positively be prolonged and improved upon. Let me know within the feedback in case you strive it out!

The dataset for this venture was studying information from my private Goodreads account; it may be downloaded from my GitHub repo. In case you use Goodreads, you’ll be able to export your individual information in CSV format, substitute it for the dataset offered, and discover it with the code for this tutorial.

Earlier than I began the venture, I filtered the dataset to retain solely books with an ISBN, since that can be utilized with Google Books API to retrieve further information a few ebook, resembling the duvet graphics and detailed class data. This venture doesn’t reap the benefits of the Books API, however by together with ISBN information within the dataset, there’s scope to increase the prototype venture in future, which is among the potential extensions I discussed above.

OpenAI

Components of this tutorial use OpenAI fashions by means of Vizro-AI. To run by means of these steps your self, it’s essential to have an OpenAI account with paid-for credit accessible. Not one of the free accounts will suffice. Examine the OpenAI fashions and pricing on their web site. The latter elements of the tutorial take the generated code and work with that, and also you don’t want a key for these.

Be aware: Earlier than utilizing a generative AI mannequin, please evaluate OpenAI’s pointers on threat mitigation to grasp potential mannequin limitations and greatest practices. See the OpenAI web site for extra particulars on accountable utilization.

In step one, I take advantage of a hosted model of Vizro-AI, discovered at https://py.cafe/app/vizro-official/vizro-ai-charts. To see it for your self, navigate to the positioning, which appears as follows:

Settings

The hyperlink will open with a settings pane the place you’ll be able to set the API key on your chosen vendor. On the time of writing, you need to use OpenAI, Anthropic, Mistral, or xAI:

To return to those settings at any time, you’ll discover a cog icon on the high proper hand nook for entry to them.

As soon as the API key’s set, return to the principle display and add the info for the venture, which is saved right here. Now you need to use Vizro-AI to construct some charts by iterating textual content to type efficient prompts.

Chart 1: Books timeline

To ask Vizro-AI to construct a chart, describe what you wish to see. The primary chart ought to present an ordered horiontal timeline as an instance the sequence of studying the books.

Plot a chart with the title “Sequence of studying” . It’s a scatter chart. Use the x axis to point out the date a ebook was learn. Plot it at y=1.

The plot appears as follows:

It’s not good! Hovering over every level gave the date the ebook was learn, however not the title of the ebook, though this might be achieved by tweaking the immediate to ask explicitly for explicit fields within the hover textual content. You’ll additionally discover that the factors are spaced evenly quite than proportionately.

The code to generate the plot is proven beneath the immediate. Right here it’s for simple entry:

Chart 2: Studying velocity

The second chart ought to plot the cumulative whole of pages learn and the cumulative whole of books learn per 12 months. The immediate took a number of iterations to refine:

Plot a chart with the title “Pages and E-book totals” .
It reveals the cumulative whole variety of pages learn by summing the
Variety of Pages of every ebook learn in every year, utilizing the Date Learn information.
Plot date on the x axis and the variety of pages on the y axis
utilizing a scale on the left hand aspect of the chart.

Superimpose a bar chart displaying the overall books learn for every year,
taking information from the Date Learn column.
Present the overall books learn utilizing the best hand aspect of the chart,
which is usually a completely different scale to the y axis proven on the left hand aspect.

The Plotly code generated with gpt-4-turbo was as follows:

The chart might be improved by bringing the road graph on high of the bar chart, however various the immediate to make this express didn’t have the specified outcomes:

Chart 3: Critiques comparability

The third chart ought to illustrate the distinction between the score the Goodreads reader assigned a ebook and the typical score throughout the Goodreads group. This immediate took a level of iteration and wanted me to specify how to attract the traces between the factors, which is a key studying when utilizing generative AI: your outcomes will range from run to run. The kind of chart (“dumbbell”) was given explicitly to information the chart creation.

For every row, create a dumbbell chart to point out the distinction between My Score and Common Score for every ebook. Use shapes so as to add the horizontal traces between markers. Omit the legend. Don’t present any row the place My Score is 0.

The plot appears as follows:

Arrange a Jupyter Pocket book

At this level, I’ve prototypes for 3 Plotly charts for the Goodreads information. To show these as an interactive dashboard, I would like some further code and Vizro-AI can generate this for me, however not by means of the appliance hosted on PyCafe (on the time of writing). I’ll use a Jupyter Pocket book as a substitute.

Earlier than operating the Pocket book code, arrange Vizro-AI inside a digital atmosphere with Python 3.10 or later. Set up the package deal with pip set up vizro_ai.

You want to give Vizro-AI your API key to entry OpenAI by including it to your atmosphere so the code you write within the subsequent step can entry it to efficiently name OpenAI. There are some easy directions within the OpenAI docs, and the method can also be coated in Vizro’s LLM setup information.

Construct a dashboard

Now open a Jupyter Pocket book to submit a single immediate that mixes the three prompts listed above, with some small edits to ask for a dashboard that has three pages: one for every chart.

The next reveals the code to make the request to Vizro-AI to construct and show the dashboard. The information manipulation has been omitted however the full Pocket book is on the market for obtain from my repo:

Utilizing gpt-4-turbo, Vizro-AI generates a set of Plotly chart code and the mandatory Vizro assist code to construct a dashboard. The generated code is displayed as output within the Pocket book with the dashboard, though the dashboard is best considered at http://localhost:8006/.

Add dashboard interactivity

To make the Vizro dashboards extra interactive, I’ll ask Vizro-AI so as to add the code for a management. As a easy instance, let’s prolong the immediate to ask for a date picker management to switch the time interval displayed for the Date Learn column and alter the dimensions on the x axis of the primary chart.

user_question = """
Create a dashboard with 3 pages, one for every chart.

On the primary web page, plot a chart with the title "Sequence of studying" .
It's a scatter chart. Use the x axis to point out the date a ebook was learn. Plot it at y=1.

+ Add a date picker filter so the person can regulate the vary of dates for the Date Learn on the x axis.

On the second web page, plot a chart with the title "Pages and E-book totals" .
It reveals the cumulative whole variety of pages learn by summing the Variety of Pages of every ebook learn in every year, utilizing the Date Learn information.
Plot date on the x axis and the variety of pages on the y axis utilizing a scale on the left hand aspect of the chart.
Superimpose a bar chart displaying the overall books learn for every year, taking information from the Date Learn column.

Present the overall books learn utilizing the best hand aspect of the chart which is usually a completely different scale to the y axis proven on the left hand aspect.

On the third web page, for every row, create a dumbbell chart to point out the distinction between My Score and Common Score for every ebook.
Use shapes so as to add the horizontal traces between markers. Omit the legend. Do not present any row the place My Score is 0.
"""

Get the Pocket book

You possibly can see the code output within the Pocket book saved on GitHub and I’ll reproduce it within the subsequent part beneath. You can too generate comparable output by operating it your self, though it won’t essentially be an identical due to the variability of outcomes returned from generative AI.

The charts Vizro-AI generated have been much like these created by the PyCafe host above, though the primary chart was improved. The books are spaced proportionately to the date I learn them, and the hover textual content included the ebook title in addition to the date learn, with out an express request to take action.

Now I’ve a Pocket book with code to name Vizro-AI to construct a prototype Vizro dashboard with a set of three pages and three charts, plus a management to filter the view.

As a result of the code generated by Vizro-AI can range from run to run, and calling OpenAI every time a dashboard is required can get pricey, it is sensible to transform the generated code into its personal venture. So I’ve transferred the generated code from the output of Vizro-AI within the Pocket book right into a PyCafe venture.

There are three adjustments to the Pocket book code wanted for it to run on PyCafe:

  1. Add from vizro import Vizro to the imports listing
  2. Add Vizro().construct(mannequin).run() on the finish of the code block
  3. Uncomment the info supervisor code and change it with code wanted to entry the filtered_books.csv dataset.

Extra about PyCafe

In case you’ve not used it earlier than, PyCafe is a free platform to create and share Python net purposes, like Vizro dashboards, in addition to Streamlit, and Sprint purposes, by means of an online browser. It grew out of a have to share Solara code snippets, and talk with customers, and was launched in June this 12 months. It’s based mostly on the open-source pyodide venture.

To get up to now, I used Vizro-AI to generate a set of charts by iterating prompts. I then transformed the profitable prompts to construct a Vizro dashboard utilizing Vizro-AI in a Pocket book utilizing a number of traces of assist code. Lastly, I transformed the generated Python to a PyCafe venture with a number of further traces of assist code, eradicating the dependency on OpenAI in doing so, and making the venture simpler to share.

It’s true that the code generated by Vizro-AI doesn’t make an ideal dashboard, however it has been very straightforward to get it to an inexpensive prototype. Let’s have a look at a number of enhancements to the Plotly code to additional enhance the charts, as proven beneath in a separate PyCafe venture.

On this model of the dashboard, the primary chart that reveals the sequence of books learn has been modified to enhance the data provided when hovering over some extent, and the opacity of the factors has been altered to make it extra enticing. The management has been modified to a slider for the Date Learn subject.

Within the second chart to point out the cumulative whole of pages and books learn, the road chart has been explicitly plotted on high of the bar chart.

Within the third chart that reveals the scores comparability, the colour scheme has been up to date to make it clearer which is the My Score worth in comparison with the Common Score.

Observe this hyperlink to check out the dashboard in full app mode.