Skip to content

How to run Vizro-AI

This guide offers insights into different ways of running VizroAI.plot to generate Plotly charts. We cover how to use:

Jupyter Notebook

To run Vizro-AI code in a Jupyter Notebook, create a new cell and execute the code below to render the described visualization as output.

Note: API key

Make sure you have followed the LLM setup guide and that your api key is set up in a .env file in the same folder as your Notebook file (.ipynb).

Ask Vizro-AI to generate a bar chart

import vizro.plotly.express as px
from vizro_ai import VizroAI

vizro_ai = VizroAI()

df = px.data.gapminder()
vizro_ai.plot(df, "visualize the life expectancy per continent and color each continent")

BarChart

Note that if you run this code, its appearance may not precisely resemble the one displayed, as it is generated by a generative AI and can vary.

Python script

You can use Vizro-AI in any standard development environment by creating a .py file and executing the code, which displays the output in a browser window. As Vizro-AI returns the fig object, you need to append fig.show() to the response object.

Note: API key

Make sure you have followed LLM setup guide and that your API key is set up in the environment where your .py script is running with command as below:

export OPENAI_API_KEY="your api key"

Ask Vizro-AI to generate a line chart

import vizro.plotly.express as px
from vizro_ai import VizroAI

vizro_ai = VizroAI()

df = px.data.gapminder()
fig = vizro_ai.plot(df, "describe life expectancy per continent over time")
fig.show()

LineChart

Application integration

You may prefer to integrate Vizro-AI into an application that offers a UI for users to input prompts. For that you can take the fig object from the .plot call, and use it elsewhere in any application (you might also want to process it further, for example, by serializing it or similar). It is also possible to obtain the code that would produce the object. For any advanced usage options, refer to our advanced options guide.