โ๏ธ Approximate time to complete: 15 min.
In this tutorial you will learn how to add custom visualizations to your Nextmv run output, so you can view interactive charts and maps directly in the Console. Complete this tutorial if you:
- Have a working Nextmv Python application.
- Want to attach Plotly charts to run output.
- Are fluent using Python ๐.
At a high level, this tutorial will go through the following steps:
- Understand assets and visuals.
- Add a Plotly bar chart to a knapsack app.
- Run locally and inspect the output.
- View the visualizations in Console.
Let's dive right in ๐คฟ.
1. Prerequisites
You need a working Nextmv Python application. If you don't have one, clone the python-highs-knapsack community app:
Install the required packages:
2. Understand assets and visuals
Before writing code, let's review the key concepts:
nextmv.Assetโ a piece of data attached to run output. An asset has a name, content, and an optional visual definition.nextmv.Visualโ defines how an asset renders in the Console. It includes a schema and a label for the tab.nextmv.VisualSchemaโ determines the rendering engine. Three schemas are available:PLOTLY,GEOJSON, andCHARTJS.
When you include assets in your nextmv.Output, they appear as custom tabs in the Console run details view. Each tab is labeled with the label you provide in the Visual.
The visual_type defaults to "custom-tab", which is the only supported type currently. The content_type defaults to "json", also the only supported type.
3. Add a Plotly bar chart
Starting from the knapsack app, update main.py to add a bar chart that shows the selected items by value and weight. Here is the full updated main.py:
The content field for Plotly assets is a list of figure JSON objects. You can include multiple figures in a single asset, and they will all render in the same tab.
4. Run locally and inspect
Run the application locally to verify the asset is included in the output:
Open the .nextmv folder and select the runID (e.g. local-6b1sdi64). Expand the visuals folder and inspect the generated html plot. Expand the outputs/assets folder and look for assets.json. It contains the Plotly figure JSON alongside the visual metadata:
5. View in Console
Push your application to Nextmv Cloud and create a run to see the visualizations in the Console:
Navigate to the run details in the Console. You will see the custom tabs alongside the default tabs:
Plotly charts are fully interactive. You can hover over bars to see values, zoom in, pan, and use the Plotly toolbar.
๐๐๐ Congratulations, you have finished this tutorial!
You now know how to attach custom visualizations to your Nextmv run output.