Linkr
Home Resources Tools Documentation Blog Demo
FR
  • What is Linkr?
  • Deployment modes
  • Quick start
  • Local install
  • With Docker
  • Manual install
  • Client-only
  • Your first project
  • Workspaces and projects
  • The data pipeline
  • Entities and sharing
  • Versioning and collaboration
  • Overview
  • Projects
  • Wiki
  • Plugins
  • Members and roles
  • Settings
  • Schemas
  • Databases
  • Derived sub-databases
  • Data quality
  • Data catalog
  • SQL script collections
  • ETL pipelines
  • Overview
  • Mapping projects
  • Global view
  • Target concepts
  • Mapping editor
  • Suggestions
  • Evaluation
  • Export
  • Overview
  • Concepts
  • Cohorts
  • Patient data
  • Pipeline
  • Datasets
  • IDE
  • Web apps
  • Versioning
  • Overview
  • Tabs and widgets
  • Built-in widgets
  • Analysis widgets
  • Control charts (SPC)
  • Surveys and eCRF
  • R and Python code
  • Filters, settings and export
  • Overview
  • Presentation mode
  • Exporting a report
  • Agents
  • Model providers
  • Skills
  • Authoring through MCP
  • Import and export
  • Git versioning
  • Community catalog
  • Publishing content
  • Production install
  • Configuration
  • Authentication and permissions
  • Files on the server
  • Backup and restore
  • Glossary
  • Keyboard shortcuts
  • Release notes
Documentation Dashboards R and Python code

R and Python code

Write your own R or Python code in a widget to produce custom output.

Summary

When no built-in widget fits, write your own R or Python code directly in a widget. The code receives your filtered dataset in a dataset variable, and its output can be a chart, a table, a value or HTML.

Client Available in client-only mode — runs entirely in the browser, no backend. Backend Backend (FastAPI) under development.

Why a code widget

The catalogue plugins cover common analyses, but sometimes you need a specific computation: a custom transformation, a chart with a particular library, a composite indicator. By choosing the Custom code tab in the Add a widget dialog, you write exactly what you want, without leaving the dashboard.

demo.linkr.interhop.org
Custom python
table_agregee.csv
Code Run
1import matplotlib.pyplot as plt
2
3ax = dataset["age"].hist(bins=20)
4ax.set_xlabel("Age")
5plt.show()
Preview: 358 × 230 px24 × 12 cells

Age

A code widget: the editor on the left (Python or R), the result preview on the right.

Choosing the language

In the Custom code tab, choose Python or R. The best language depends on your habits and the task:

  • Python builds on the pandas / matplotlib ecosystem for data wrangling and visualisation.
  • R suits statistical analyses and ggplot2 / base R graphics.

Why no SQL?

Code widgets offer Python and R, but not SQL. A widget works on a dataset — a file, not a database connection — so a SQL query would have nothing to query. For SQL, address the database itself from the SQL script collections.

Where the code runs

In client mode (no backend), the code runs in your browser thanks to WebAssembly ports: Pyodide for Python and WebR for R. Your data never leaves the machine. The first run loads the environment (a few seconds); later runs are faster.

In server mode, the code runs on the server: it reads the dataset and applies the dashboard filters itself, so no data rows are sent to the browser. Each widget runs in its own process, so the widgets of a tab execute in parallel. See the deployment modes.

Accessing the data

Your code automatically receives the widget’s dataset, already filtered by the dashboard’s active filters:

  • In Python, the variable dataset is a pandas DataFrame. Columns keep their readable names (e.g. dataset["age"]).
  • In R, the variable dataset is a data.frame with the same columns.

So you just read dataset and produce your output.

import matplotlib.pyplot as plt

ax = dataset["age"].hist(bins=20)
ax.set_xlabel("Age")
ax.set_ylabel("Count")
plt.show()
library(ggplot2)

ggplot(dataset, aes(x = age)) +
  geom_histogram(bins = 20) +
  labs(x = "Age", y = "Count")

Filters apply before your code

The dataset your code receives already reflects the dashboard’s filters. When the user changes a filter, the code widget re-runs on the new rows — your code does not need to do anything special.

Output types

The widget renders whatever your code produces:

Chart

A matplotlib / ggplot / base R figure, rendered as a crisp image (vector when possible).

Table

A DataFrame or data.frame shown as a table.

Value

A printed number or text — useful for a simple indicator.

HTML

Raw HTML, for a custom rendering directly in the widget.

If something goes wrong, the standard output and error messages (stdout / stderr) appear in the widget to help you fix it.

One-off code or reusable plugin?

A code widget is ideal for a one-off analysis specific to a dashboard. If you find yourself copying the same code from project to project, package it as a plugin instead: it becomes configurable, shareable and shows up in the widget list. See Build a plugin.

PreviousSurveys and eCRFNextFilters, settings and export

Product

  • Home
  • Demo

Resources

  • Documentation
  • Resources
  • Tools
  • Blog

Community

  • Framagit source code
  • Github source code

About

  • InterHop.org
  • Contact

2021–2026 InterHop — CC BY-NC-SA 4.0 (site) · GPLv3 (software)