Linkr
Home Resources Tools Documentation Blog Demo
FR
  • What is Linkr?
  • Deployment modes
  • Quickstart
  • Local install
  • Your first project
  • Workspaces and projects
  • The data pipeline
  • Versioning and collaboration
  • Schemas WIP
  • Databases WIP
  • Data quality WIP
  • ETL pipelines WIP
  • Concept mapping
  • Introduction
  • Mapping projects
  • Overview
  • Target Concepts
  • Mapping Editor
  • Suggestions
  • Evaluation
  • Export
  • Data catalog WIP
  • Cohorts WIP
  • Patient-level data WIP
  • Datasets WIP
  • Script collections WIP
  • IDE WIP
  • Dashboards
  • Reports WIP
  • Build a plugin WIP
  • Overview
  • Tabs and widgets
  • Built-in widgets
  • R, Python and SQL code
  • Filters, settings and export
  • Wiki WIP
  • Versioning WIP
  • Production install WIP
  • Authentication and permissions WIP
  • Configuration WIP
  • Backup and restore WIP
  • Glossary WIP
  • Release notes WIP
Documentation Dashboards R, Python and SQL code

R, Python and SQL code

Write your own R, Python or SQL code in a widget to produce custom output, run in the browser.

Summary

When no built-in widget fits, write your own R, Python or SQL 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.

linkr-v2-b1800b.frama.io
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, R or SQL), the result preview on the right.

Choosing the language

In the Custom code tab, choose Python, R or SQL. 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.
  • SQL is for querying and aggregating the dataset declaratively.

Client mode: everything in the browser

In client mode (no backend), the code runs in your browser thanks to WebAssembly ports: Pyodide for Python, WebR for R, and DuckDB-WASM for SQL. Your data then never leaves the machine. The first run loads the environment (a few seconds); later runs are faster. With a backend, execution can happen server-side — 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.

PreviousBuilt-in widgetsNextFilters, 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)