R and Python Charting

R and Python are powerful languages that can be used for more advanced statistical data manipulation such as predictive analytics or to create more specific chart formats. With the R and Python integration, Periscope will automatically pull the results of your SQL into R and Python to enable statistical analysis, all within the chart editor.

Note: R and Python Integration is an add-on feature. Site administrators can contact their Account Manager for additional information.

Available Libraries

Additionally, you can easily access the libraries available to import from the schema browser and link directly to the library docs.

Python 2.7 and Python 3.6 supported libraries include:

R supported libraries:

More libraries will be added as they are requested and reviewed. Please reach out to Periscope Data support to request a library addition at support@periscopedata.com or over the in-app live chat.

Adding Python to the Chart

Once a SQL query has been successfully run for a new chart, select the desired language from the dropdown below the SQL editor and click the '+' icon to add a block of code. Periscope currently supports Python 2.7, Python 3.6 and R (see below). 

For Python, the pandas library has already been imported pd, with the result set of the chart imported as a pandas dataframe variable called "df". 

In the schema, you can easily see the data frame columns along with the data type.

If the code outputs another dataframe (df2) to be used by Periscope Data's charting functionality, the dataframe can be passed to periscope.output with the following syntax:

periscope.output(df2)

Similarly, for code that generates a plot (named plt), the plot can be passed to periscope.output like this, which would replace the common plt.show():

periscope.output(plt)

Data and text can also be printed to the Standard Out. Switching between the Periscope Output and the Standard Out can be done with the tabs below the code block Run button.

To use the Periscope Output or the Standard Out directly in a chart, select "Python Image" or "Python Text" respectively in the chart type drop down.

Adding R to the Chart

Select R from the dropdown below the SQL editor and click the '+' icon to add a block of code.

For R, the result set of the chart is imported as a dataframe variable called "df". 

If the code outputs another dataframe (named df2) to be used by Periscope Data's charting functionality, the dataframe can be passed to periscope.table with the following syntax:

periscope.table(df2)

Similarly, for code that generates a plot, the plot can be output by calling periscope.image() after plotting. For images, the Periscope chart will scale the size of the image according to the chart's bounds. To define an image's height and width, an optional png function call can override the defaults:

plot(df)
png(width=500, height=500, unit='px)
periscope.image()

Lastly, for code that generates text (named txt), the text can be passed to periscope.text like this:

periscope.text(txt)

Data and text can also be printed to the Standard Out. Switching between the Periscope Output and the Standard Out can be done with the tabs below the code block Run button.

To use the Periscope Output or the Standard Out directly in a chart, select "R Image" or "R Text" respectively in the chart type drop down.

Limit Preview

Most browsers can only handle visualizations of up to 5MB, so to keep dashboards running smoothly, visualization results are capped. Once a code block for R or Python is added to a chart, the “Limit Preview” setting for charts will only apply to the SQL Output preview. The “Limit Preview” setting will not affect the rows or size of the dataframe sent to the R or Python script, allowing the code to run on the full result set within a 500MB limit. If the R or Python code returns over 5MB of data, an error will be surfaced and a hard-coded limit or aggregation, outside of the “Limit Preview” setting, should be added to the SQL or code blocks.

Our support team is ready to help.