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.
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.
Age
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
datasetis a pandas DataFrame. Columns keep their readable names (e.g.dataset["age"]). - In R, the variable
datasetis 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.
Someone else’s code: review it before it runs
In server mode, a dashboard starts its code widgets as soon as it opens, on the server and with your access. That code may come from an import, a git repository, a colleague: so Linkr does not run it on your behalf before you have read it.
The first time a piece of code reaches you — imported, last changed by someone else, or never run by you —, a Review this code before it runs window shows it in full. When a dashboard holds several, they are all listed in the same window.
- Accept and run — the code runs, and your answer is remembered until its text changes.
- Do not run — the widget shows “Not run: you have not accepted this code.” The window does not come back on its own; it opens again when you run the widget again.
Code you write yourself and run from the editor asks nothing. The same rule applies to a dataset’s analyses and to the plugins of a patient board.
One acceptance per person
Each member accepts for themselves: the code runs with their access, not with its author’s. An API key or an agent connected through the MCP server cannot accept on your behalf.
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.