Debian Codegraph @

examples/HtmlRenderer.ipynb

raw
1 {
2 "cells": [
3 {
4 "cell_type": "code",
5 "execution_count": 1,
6 "id": "f2b527c8-901e-488f-b08e-ae3daa4cf4a1",
7 "metadata": {},
8 "outputs": [],
9 "source": [
10 "import json\n",
11 "\n",
12 "import numpy as np\n",
13 "import pandas as pd\n",
14 "from bqplot import ColorScale\n",
15 "\n",
16 "from ipydatagrid import Expr, DataGrid, TextRenderer, BarRenderer, HtmlRenderer"
17 ]
18 },
19 {
20 "cell_type": "code",
21 "execution_count": 10,
22 "id": "3d2537f5-ae31-4ccb-bc74-700b08f85bcc",
23 "metadata": {},
24 "outputs": [],
25 "source": [
26 "n = 5\n",
27 "\n",
28 "df = pd.DataFrame(\n",
29 " {\n",
30 " \"Value 1\": [1, 2, 3, 4, 5],\n",
31 " \"Value 2\": '<ol><li>Item 1</li><li>Item 2</li><li>Item 3</li></ol>',\n",
32 " \"Value 3\": '<p><strong style=\"color: olive\">Bold Text</strong></p><p><em style=\"background-color: yellow\">Italic Text</em></p><p><u>Underlined Text</u></p><p><s>Strikethrough Text</s></p>'\n",
33 " }\n",
34 ")"
35 ]
36 },
37 {
38 "cell_type": "code",
39 "execution_count": 11,
40 "id": "e6ec592c-5811-487c-bd8a-b2a3b14e892e",
41 "metadata": {},
42 "outputs": [],
43 "source": [
44 "text_renderer = TextRenderer(\n",
45 " text_color=\"black\", background_color=ColorScale(min=-5, max=5)\n",
46 ")\n",
47 "\n",
48 "html_renderer = HtmlRenderer(text_color='blue', background_color='aliceblue', horizontal_alignment='right', vertical_alignment='bottom')\n",
49 "\n",
50 "renderers = {\n",
51 " \"Value 1\": text_renderer,\n",
52 " \"Value 2\": html_renderer,\n",
53 " \"Value 3\": html_renderer,\n",
54 " \n",
55 "}"
56 ]
57 },
58 {
59 "cell_type": "code",
60 "execution_count": 12,
61 "id": "9113bdb2-92a4-46ec-bcf0-ad350616fcea",
62 "metadata": {},
63 "outputs": [],
64 "source": [
65 "grid = DataGrid(df, renderers=renderers,base_row_size=140, base_column_size=100)"
66 ]
67 },
68 {
69 "cell_type": "code",
70 "execution_count": 13,
71 "id": "ea4d76ec-9efe-41c3-84cb-399c46b53f02",
72 "metadata": {},
73 "outputs": [
74 {
75 "data": {
76 "application/vnd.jupyter.widget-view+json": {
77 "model_id": "750bcc6f601d4d79876995609422dd1e",
78 "version_major": 2,
79 "version_minor": 0
80 },
81 "text/plain": [
82 "DataGrid(auto_fit_params={'area': 'all', 'padding': 30, 'numCols': None}, base_column_size=100, base_row_size=…"
83 ]
84 },
85 "execution_count": 13,
86 "metadata": {},
87 "output_type": "execute_result"
88 }
89 ],
90 "source": [
91 "grid"
92 ]
93 },
94 {
95 "cell_type": "code",
96 "execution_count": null,
97 "id": "dd2dfa48-2624-4258-b2fa-dc759adf20e0",
98 "metadata": {},
99 "outputs": [],
100 "source": []
101 }
102 ],
103 "metadata": {
104 "kernelspec": {
105 "display_name": "Python 3 (ipykernel)",
106 "language": "python",
107 "name": "python3"
108 },
109 "language_info": {
110 "codemirror_mode": {
111 "name": "ipython",
112 "version": 3
113 },
114 "file_extension": ".py",
115 "mimetype": "text/x-python",
116 "name": "python",
117 "nbconvert_exporter": "python",
118 "pygments_lexer": "ipython3",
119 "version": "3.12.2"
120 }
121 },
122 "nbformat": 4,
123 "nbformat_minor": 5
124 }