Spaces:
Sleeping
Sleeping
File size: 2,974 Bytes
d6ca999 4176ac6 d6ca999 114e433 955dcbf 9c65f5c 955dcbf 62ec136 4176ac6 62ec136 d6ca999 62ec136 4176ac6 62ec136 4176ac6 62ec136 4176ac6 955dcbf 62ec136 d6ca999 62ec136 d6ca999 62ec136 d6ca999 62ec136 d6ca999 955dcbf 4176ac6 955dcbf 114e433 955dcbf dc22d3c 114e433 dc22d3c 69cfba9 d6ca999 4176ac6 d6ca999 |
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 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "1226e7e9",
"metadata": {},
"outputs": [],
"source": [
"# import ipyvizzu and ipyvizzu-story\n",
"\n",
"from ipyvizzu import Data, Config\n",
"from ipyvizzustory import Slide, Step\n",
"\n",
"from ipyvizzustory import Story # or\n",
"# from ipyvizzustory.env.ipy.story import Story\n",
"\n",
"from IPython.display import display as display_html, HTML\n",
"\n",
"import mercury as mr\n",
"\n",
"\n",
"# setup Mercury App\n",
"app = mr.App(\n",
" title=\"ipyvizzu-story demo\", description=\"ipyvizzu-story demo with mercury\"\n",
")\n",
" \n",
"# add widget\n",
"selected = mr.MultiSelect(\n",
" label=\"Select what you want to see\", value=[\"animation\"], choices=[\"animation\", \"code\"]\n",
")\n",
"\n",
"\n",
"# create data and initialize Story with the created data\n",
"\n",
"data = Data()\n",
"data.add_series(\"Foo\", [\"Alice\", \"Bob\", \"Ted\"])\n",
"data.add_series(\"Bar\", [15, 32, 12])\n",
"data.add_series(\"Baz\", [5, 3, 2])\n",
"\n",
"# you can also add data with pandas\n",
"\n",
"# import pandas as pd\n",
"#\n",
"# data = Data()\n",
"# df = pd.read_csv(\n",
"# \"https://raw.githubusercontent.com/\" +\n",
"# \"vizzuhq/ipyvizzu-story/main/\" +\n",
"# \"docs/examples/basic/basic.csv\"\n",
"# )\n",
"# data.add_data_frame(df)\n",
"\n",
"story = Story(data=data)\n",
"\n",
"# create Slides and Steps and add them to the Story\n",
"\n",
"slide1 = Slide(\n",
" Step(\n",
" Config({\"x\": \"Foo\", \"y\": \"Bar\"}),\n",
" )\n",
")\n",
"story.add_slide(slide1)\n",
"\n",
"slide2 = Slide(\n",
" Step(\n",
" Config({\"color\": \"Foo\", \"x\": \"Baz\", \"geometry\": \"circle\"}),\n",
" )\n",
")\n",
"story.add_slide(slide2)\n",
"\n",
"# you can set the width and height (CSS style)\n",
"\n",
"story.set_size(width=\"800px\", height=\"480px\")\n",
"\n",
"# you can get the html Story as a string\n",
"\n",
"html = story.to_html()\n",
"\n",
"if \"animation\" in selected.value:\n",
" story.play()\n",
"if \"code\" in selected.value:\n",
" display_html(html)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.7.3 64-bit",
"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.10.4"
},
"vscode": {
"interpreter": {
"hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|