Spaces:
Sleeping
Sleeping
File size: 6,957 Bytes
dfff3a1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "f11fb0aa-9798-42c4-8045-89a17119a7b5",
"metadata": {},
"outputs": [],
"source": [
"import manganite\n",
"%load_ext manganite"
]
},
{
"cell_type": "markdown",
"id": "93cd20ee-490f-449e-8d26-dce9f1940993",
"metadata": {},
"source": [
"# Widget Showcase\n",
"\n",
"This notebook presents all widget types available in Manganite. Feel free to copy their code and use it in your own dashboards.\n",
"\n",
"The `%%mnn widget` magic command has the following structure:\n",
"\n",
"```bash\n",
"%%mnn widget --type TYPE [PARAMS] --tab TAB [--position ROW COL SPAN] --header HEADER --var VAR_NAME\n",
"```\n",
"\n",
"where `TYPE` and optional `PARAMS` define the widget, `TAB`, `ROW`, `COL` and `SPAN` determine where to place it, and `HEADER` gives it a title above. `VAR_NAME` has to refer to an existing variable (can be defined in the same cell) of matching type (`bool` for a checkbox, `int` or `float` for a slider, etc.)\n",
"\n",
"`PARAMS` can take various forms, depending on widget type. Select boxes and radio buttons accept a variable holding their options (a collection of strings, can be any of `list`, `tuple`, `set`). Sliders take three numeric parameters, in the format of `MIN:MAX:STEP`. File pickers accept an optional string describing allowed file types, as defined for the `accept` attribute of the corresponding [HTML element](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6f124879-338f-4da6-ac9c-ae6a0593d621",
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"import pandas as pd\n",
"list_of_options = ['option a', 'option b', 'option c']"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "605179e0-d800-46a8-86ed-f23172d778c3",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type checkbox --tab \"Options\" --header \"Checkbox\" --var b_1\n",
"b_1 = True"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b10f338c-584b-4766-9ee3-268efadaf2f7",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type switch --tab \"Options\" --header \"Switch\" --var b_2\n",
"b_2 = False"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5cd14108-e3a2-4d3f-b319-a2fa908f6735",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"%%mnn widget --type select list_of_options --tab \"Options\" --header \"Select\" --var s\n",
"s = list_of_options[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8ec0923b-8fda-418c-a2b7-a7d9d85cbd2c",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type radio list_of_options --tab \"Options\" --header \"Radio buttons\" --var r\n",
"r = list_of_options[1]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "aa3169ae-6060-45f6-ae92-f7d8869288a0",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type slider 0:100:1 --tab \"Numbers\" --position 0 0 6 --header \"Int slider\" --var i\n",
"i = 42"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1fe24fc2-6db7-46e0-b5bf-7adf4978987a",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type text --tab \"Numbers\" --header \"Int input\" --var j\n",
"j = -128"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "94e20a08-e77d-4d15-a299-e69dc1b4a29c",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type slider -4:4:0.01 --tab \"Numbers\" --position 1 0 6 --header \"Float slider\" --var f\n",
"f = 3.14"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "892d031c-caad-4430-af09-10e5269368ad",
"metadata": {
"editable": true,
"slideshow": {
"slide_type": ""
},
"tags": []
},
"outputs": [],
"source": [
"%%mnn widget --type text --tab \"Numbers\" --header \"Float input\" --var g\n",
"g = 9.99"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6a7ecf24",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type text --tab \"Strings\" --header \"String input\" --var st\n",
"st = 'Hello manganite'"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cd7001ff-f6dc-4286-9794-d3666dec0a90",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type date --tab \"Dates\" --header \"Date\" --var d\n",
"d = datetime.date.today()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "20734b96-2c9c-46d9-8547-d717ce8f5c13",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type datetime --tab \"Dates\" --header \"Datetime\" --var dt\n",
"dt = datetime.datetime.now()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "fffdb0a9-8115-4675-952d-5983545dc478",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type table --tab \"Pandas\" --position 0 0 6 --header \"DataFrame\" --var df\n",
"df = pd.read_excel('SupplierSourcing.xlsx',index_col=0)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9b40f9b7-7f04-4702-9ee7-097fb171e01e",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type file --tab \"Files\" --position 0 0 3 --header \"File picker (any file)\" --var file_path\n",
"file_path = '' # initial value is ignored"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "723ee2a1-39ce-4f3a-99ea-f10eebccae1a",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type file '.csv' --tab \"Files\" --position 0 3 3 --header \"File picker (only CSV)\" --var csv_path\n",
"csv_path = '' # initial value is ignored"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cd9d0f32-d91c-4ac7-bc32-a81fb91697c4",
"metadata": {},
"outputs": [],
"source": [
"%%mnn widget --type table --tab \"Files\" --position 1 0 6 --header \"CSV preview\" --var csv_df\n",
"csv_df = pd.read_csv(csv_path) if csv_path else pd.DataFrame() # show empty DataFrame if no file selected"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.0"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|