Debian Codegraph @

examples/HyperlinkRenderer.ipynb

raw
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": null,
24 "id": "separate-mattress",
25 "metadata": {},
26 "outputs": [],
27 "source": [
28 "import pandas as pd\n",
29 "import numpy as np\n",
30 "from ipydatagrid import VegaExpr, DataGrid, TextRenderer, HyperlinkRenderer\n",
31 "\n",
32 "df = pd.DataFrame(\n",
33 " data={\n",
34 " \"Name\": [\"NumFocus\"],\n",
35 " \"Link\": [[\"https://numfocus.org/\", \"Better tools to build a better worlds.\"]],\n",
36 " }\n",
37 ")\n",
38 "\n",
39 "link_renderer = HyperlinkRenderer(\n",
40 " url=VegaExpr(\"cell.value[0]\"),\n",
41 " url_name=VegaExpr(\"cell.value[1]\"),\n",
42 " background_color=\"moccasin\",\n",
43 " text_color=\"blue\",\n",
44 " font=\"bold 14px Arial, sans-serif\",\n",
45 ")\n",
46 "\n",
47 "\n",
48 "grid = DataGrid(\n",
49 " df,\n",
50 " layout={\"height\": \"120px\"},\n",
51 " base_column_size=200,\n",
52 " renderers={\"Link\": link_renderer},\n",
53 ")\n",
54 "grid"
55 ]
56 }
57 ],
58 "metadata": {
59 "kernelspec": {
60 "display_name": "Python 3",
61 "language": "python",
62 "name": "python3"
63 },
64 "language_info": {
65 "codemirror_mode": {
66 "name": "ipython",
67 "version": 3
68 },
69 "file_extension": ".py",
70 "mimetype": "text/x-python",
71 "name": "python",
72 "nbconvert_exporter": "python",
73 "pygments_lexer": "ipython3",
74 "version": "3.9.5"
75 }
76 },
77 "nbformat": 4,
78 "nbformat_minor": 5
79 }