Parameterising a Script

Deployed scripts can be parameterised, making them a web form you can share with others


When you add parameters to your script, they are presented in your browser as web forms which users can run to generate reports. This means that people can generate reports without worrying about code, notebooks, or setting up a Python environment.

Running & Parameters

Input parameters are passed into your code at runtime and are defined in your datapane.yaml . In Python, they are accessible in the Params dictionary. You can get an item from the dictionary with Params.get([value_name], [default_value])

Let's allow users to provide the stock tickers they are interested in through a tickers parameter. To create an input for our tickers parameter on the web interface, we must add it to our datapane.yaml from the Deploying a Script section.

Full details of parameter configuration and available fields are provided in the API reference.

name: stock_plotter
script: # this could also be ipynb if it was a notebook
- name: tickers
type: list
default: ['GOOG', 'ZM']
description: "Tickers to plot"

We can then access it in our code, and use load_defaults to load in the default values from our datapane.yaml

When we are developing locally, Params is empty by default, but you can load in the default parameters from your datapane.yaml (or any other YAML file) using the following command:

import pandas as pd
import altair as alt
import datapane as dp
from scipy.stats import zscore
#tickers = ['GOOG']
tickers = dp.Params.get('tickers')
dfs = []
for t in tickers:
t_df = pd.read_csv(f'{t}?period1=1553600505&period2=1585222905&interval=1d&events=history')
t_df['ticker'] = t
stock_data = pd.concat(dfs)
stock_data['Date'] = pd.to_datetime(stock_data['Date'])
stock_data['zscore'] = stock_data.groupby('ticker')['Close'].transform(lambda x: zscore(x))
plot = alt.Chart(stock_data).encode(x='Date:T',y='zscore', color='ticker').mark_line()
report = dp.Report(
dp.Markdown("## Stock Report"),

When we run script deploy, Datapane will use configuration to generate the following form.

Users can now enter various stocks which they would like to plot, and receive a dynamic report each time.