Skip to content

Commit cf2b118

Browse files
committed
Add HyperlinkRenderer usage example
Signed-off-by: Itay Dafna <[email protected]>
1 parent 16f32a0 commit cf2b118

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

examples/HyperlinkRenderer.ipynb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "fabulous-environment",
6+
"metadata": {},
7+
"source": [
8+
"## `ipydatagrid`\n",
9+
"### HyperlinkRenderer\n",
10+
"\n",
11+
"A renderer which allows for rendering text-based clickable links as cells in your DataGrid. It takes two parameters:\n",
12+
"\n",
13+
"1. `url`: A Vega Expression function which points to a full URL (with the http(s) prefix)\n",
14+
"2. `urlName`: A Vega Expression function which points to a friendly URL display name\n",
15+
"\n",
16+
"**To preserve default cell selections behaviour, a link can only be opened by clicking whilst holding the `Ctrl` or `Command` key pressed.**\n",
17+
"\n",
18+
"The `HyperlinkRenderer` can be styled using all properties supported by the `TextRenderer`!"
19+
]
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": 36,
24+
"id": "separate-mattress",
25+
"metadata": {},
26+
"outputs": [
27+
{
28+
"data": {
29+
"application/vnd.jupyter.widget-view+json": {
30+
"model_id": "36f9e008917b4d6d96c9329d1bc3dd54",
31+
"version_major": 2,
32+
"version_minor": 0
33+
},
34+
"text/plain": [
35+
"DataGrid(base_column_size=200, corner_renderer=None, default_renderer=TextRenderer(), header_renderer=None, la…"
36+
]
37+
},
38+
"metadata": {},
39+
"output_type": "display_data"
40+
}
41+
],
42+
"source": [
43+
"import pandas as pd\n",
44+
"import numpy as np\n",
45+
"from ipydatagrid import VegaExpr, DataGrid, TextRenderer, HyperlinkRenderer\n",
46+
"\n",
47+
"df = pd.DataFrame(\n",
48+
" data={\"Name\":[\"Tech at Bloomberg\", \"Twitter Handle\"], \n",
49+
" \"Link\":[[\"https://www.techatbloomberg.com/\", \"Tech at BBG Website\"]]})\n",
50+
"\n",
51+
"link_renderer = HyperlinkRenderer(\n",
52+
" url = VegaExpr(\"cell.value[0]\"),\n",
53+
" url_name = VegaExpr(\"cell.value[1]\"),\n",
54+
" background_color=\"moccasin\",\n",
55+
" text_color=\"blue\",\n",
56+
" font='bold 14px Arial, sans-serif'\n",
57+
")\n",
58+
"\n",
59+
"\n",
60+
"grid = DataGrid(df, layout={\"height\":\"120px\"}, base_column_size=200, renderers={'Link':link_renderer})\n",
61+
"grid"
62+
]
63+
}
64+
],
65+
"metadata": {
66+
"kernelspec": {
67+
"display_name": "Python 3",
68+
"language": "python",
69+
"name": "python3"
70+
},
71+
"language_info": {
72+
"codemirror_mode": {
73+
"name": "ipython",
74+
"version": 3
75+
},
76+
"file_extension": ".py",
77+
"mimetype": "text/x-python",
78+
"name": "python",
79+
"nbconvert_exporter": "python",
80+
"pygments_lexer": "ipython3",
81+
"version": "3.9.5"
82+
}
83+
},
84+
"nbformat": 4,
85+
"nbformat_minor": 5
86+
}

0 commit comments

Comments
 (0)