Tutorial | Static insights#

Although Dataiku has a native drag-and-drop chart builder for many types of plots, in some cases, you may prefer to code your own visualization using your favorite library.

For these cases, static insights are data files generated with code in Dataiku that allow you to save and publish on a dashboard any custom figure. Let’s see how they work!

Get started#

Objectives#

In this tutorial, you will:

  • Create a static insight with a Python or R visualization library (such as plotly, matplotlib, bokeh, ggplot2, or altair).

  • Publish a static insight to a dashboard.

Prerequisites#

  • Dataiku 12.0 or later.

  • An Advanced Analytics Designer or Full Designer user profile.

  • Some familiarity with Python and/or R.

  • Basic knowledge of working with code notebooks in Dataiku.

  • A code environment that supports the visualization library you want to use. If not already available, create a code environment including the libraries required libraries for the plot you want to create. To follow the Python examples here, that might be plotly, matplotlib, bokeh, or altair. R users can use the built-in R environment.

Tip

If using Python on Dataiku Cloud, the dash code environment includes the libraries needed for visualizations in plotly, matplotlib, bokeh, and altair. R users need to activate the R extension.

Create the project#

As an example, we’ll use a dataset of transactions including a CustomerAge column.

  1. From the Dataiku Design homepage, click + New Project > DSS tutorials > Developer > Static Insights.

  2. From the project homepage, click Go to Flow (or g + f).

Note

You can also download the starter project from this website and import it as a zip file.

Create a notebook#

To create a static insight, start in a code notebook.

  1. From the Flow, select the ecommerce_transactions dataset.

  2. In the Actions panel, select the Lab.

  3. Under Code Notebooks, select New.

  4. In the dialog, select Python (or R if using ggplot2).

  5. Ensure a compatible code environment is selected.

  6. Click Create.

Dataiku screenshot of the dialog for a new notebook.

Create a chart with a visualization library#

Having created a notebook from the ecommerce_transactions dataset, Dataiku has already provided starter code creating a pandas (or R) dataframe object named df.

Regardless of which visualization library you prefer, the overall procedure is the same. We’ll provide a number of examples using popular libraries.

Tip

In addition to these, we’ve also provided a generic example using altair to illustrate cases where there is no dedicated method for saving that particular type of insight.

  1. Confirm the notebook’s kernel supports your visualization library.

  2. Import the necessary libraries at the top of the notebook.

import plotly.express as px
  1. Add the code for the actual plot, and then execute the notebook to display a plot.

fig = px.histogram(df, x='CustomerAge')
fig.show()

Save the plot as an insight#

Once you are satisfied with the plot displayed in your notebook, the next step is to save it as an insight.

  1. Those using Python need to add one more import statement. R users can skip this step.

from dataiku import insights
  1. Beneath the code for the visualization, copy-paste and run the code below to save the plot as an insight.

insights.save_plotly("plotly_insight", fig)
  1. Go to the Insights page (g + i), and open the saved insight.

Publish an insight to a dashboard#

You have now saved an insight, but it is often more useful to share it on a dashboard.

  1. From the insight, open the Actions panel.

  2. Select Add insight.

  3. If desired, adjust the default selection for the dashboard and slide, and click Pin.

  4. Go to the Dashboards page (g + p), and open the chosen dashboard.

  5. From the dashboard, click Edit to be able to adjust the insight’s size and position as needed.

Tip

Rebuilding “static” insights can be automated using the Export notebook step in a scenario.

What’s next?#

Using static insights in Dataiku, you have created, saved, and published custom visualizations.

To learn more about creating static insights with Python and R libraries, visit: