This commit is contained in:
louiscklaw
2025-01-31 20:57:47 +08:00
parent ed177c5ad6
commit fc6f79b133
341 changed files with 201064 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
jupyter = "*"
notebook = "*"
pandas = "*"
quandl = "*"
seaborn = "*"
sklearn = "*"
scikit-learn = "*"
pydot = "*"
bokeh = "*"
jupyter-bokeh = "*"
voila = "*"
bqplot = "*"
ipympl = "*"
ipyvolume = "*"
[dev-packages]
[requires]
python_version = "3"

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env bash
set -ex
python -m pip install --upgrade pip
python -m pip install pipenv
python -m pipenv install voila
python -m pipenv install bqplot
python -m pipenv install ipympl
python -m pipenv install ipyvolume
pipenv sync
pipenv run \
jupyter-notebook \
--allow-root \
--ip=0.0.0.0

View File

@@ -0,0 +1,15 @@
#!/usr/bin/env bash
set -ex
pipenv install jupyter
pipenv install jupyter notebook
pipenv install pandas
pipenv install quandl
pipenv install seaborn
pipenv install scikit-learn
# jupyter-notebook

View File

@@ -0,0 +1,248 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# So easy, *voilà*!\n",
"\n",
"In this example notebook, we demonstrate how Voilà can render Jupyter notebooks with interactions requiring a roundtrip to the kernel."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Jupyter Widgets"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9d234bc95ca5460ea86e664a957764e3",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(FloatSlider(value=4.0, description='$x$'), FloatText(value=16.0, description='$x^2$', disabled=…"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import ipywidgets as widgets\n",
"\n",
"slider = widgets.FloatSlider(description='$x$')\n",
"text = widgets.FloatText(disabled=True, description='$x^2$')\n",
"\n",
"def compute(*ignore):\n",
" text.value = str(slider.value ** 2)\n",
"\n",
"slider.observe(compute, 'value')\n",
"\n",
"slider.value = 4\n",
"\n",
"widgets.VBox([slider, text])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Basic outputs of code cells"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>sepal_length</th>\n",
" <th>sepal_width</th>\n",
" <th>petal_length</th>\n",
" <th>petal_width</th>\n",
" <th>species</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>5.1</td>\n",
" <td>3.5</td>\n",
" <td>1.4</td>\n",
" <td>0.2</td>\n",
" <td>setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>4.9</td>\n",
" <td>3.0</td>\n",
" <td>1.4</td>\n",
" <td>0.2</td>\n",
" <td>setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>4.7</td>\n",
" <td>3.2</td>\n",
" <td>1.3</td>\n",
" <td>0.2</td>\n",
" <td>setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>4.6</td>\n",
" <td>3.1</td>\n",
" <td>1.5</td>\n",
" <td>0.2</td>\n",
" <td>setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>5.0</td>\n",
" <td>3.6</td>\n",
" <td>1.4</td>\n",
" <td>0.2</td>\n",
" <td>setosa</td>\n",
" </tr>\n",
" <tr>\n",
" <th>...</th>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" <td>...</td>\n",
" </tr>\n",
" <tr>\n",
" <th>145</th>\n",
" <td>6.7</td>\n",
" <td>3.0</td>\n",
" <td>5.2</td>\n",
" <td>2.3</td>\n",
" <td>virginica</td>\n",
" </tr>\n",
" <tr>\n",
" <th>146</th>\n",
" <td>6.3</td>\n",
" <td>2.5</td>\n",
" <td>5.0</td>\n",
" <td>1.9</td>\n",
" <td>virginica</td>\n",
" </tr>\n",
" <tr>\n",
" <th>147</th>\n",
" <td>6.5</td>\n",
" <td>3.0</td>\n",
" <td>5.2</td>\n",
" <td>2.0</td>\n",
" <td>virginica</td>\n",
" </tr>\n",
" <tr>\n",
" <th>148</th>\n",
" <td>6.2</td>\n",
" <td>3.4</td>\n",
" <td>5.4</td>\n",
" <td>2.3</td>\n",
" <td>virginica</td>\n",
" </tr>\n",
" <tr>\n",
" <th>149</th>\n",
" <td>5.9</td>\n",
" <td>3.0</td>\n",
" <td>5.1</td>\n",
" <td>1.8</td>\n",
" <td>virginica</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>150 rows × 5 columns</p>\n",
"</div>"
],
"text/plain": [
" sepal_length sepal_width petal_length petal_width species\n",
"0 5.1 3.5 1.4 0.2 setosa\n",
"1 4.9 3.0 1.4 0.2 setosa\n",
"2 4.7 3.2 1.3 0.2 setosa\n",
"3 4.6 3.1 1.5 0.2 setosa\n",
"4 5.0 3.6 1.4 0.2 setosa\n",
".. ... ... ... ... ...\n",
"145 6.7 3.0 5.2 2.3 virginica\n",
"146 6.3 2.5 5.0 1.9 virginica\n",
"147 6.5 3.0 5.2 2.0 virginica\n",
"148 6.2 3.4 5.4 2.3 virginica\n",
"149 5.9 3.0 5.1 1.8 virginica\n",
"\n",
"[150 rows x 5 columns]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"iris = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv')\n",
"iris"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

View File

@@ -0,0 +1,84 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# So easy, *voilà*!\n",
"\n",
"In this example notebook, we demonstrate how Voilà can render custom Jupyter widgets such as [bqplot](https://github.com/bloomberg/bqplot). "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import warnings\n",
"warnings.filterwarnings('ignore')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "f771faf1649e425480af29391b9a238e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import numpy as np\n",
"from bqplot import pyplot as plt\n",
"\n",
"plt.figure(1, title='Line Chart')\n",
"np.random.seed(0)\n",
"n = 200\n",
"x = np.linspace(0.0, 10.0, n)\n",
"y = np.cumsum(np.random.randn(n))\n",
"plt.plot(x, y)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -0,0 +1,202 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This demo uses Voilà to render a notebook to a custom HTML page using gridstack.js for the layout of each output. In the cell metadata you can change the default cell with and height (in grid units between 1 and 12) by specifying.\n",
" * `grid_row`\n",
" * `grid_columns`"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"n = 200\n",
"\n",
"x = np.linspace(0.0, 10.0, n)\n",
"y = np.cumsum(np.random.randn(n)*10).astype(int)\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import ipywidgets as widgets"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "fb68ca2d6f7f40c2adb9d01d134a4373",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Label(value='Selected: 0')"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"label_selected = widgets.Label(value=\"Selected: 0\")\n",
"label_selected"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"grid_columns": 8,
"grid_rows": 4
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "227e65a70eab4eb38b0b2f25d8237656",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Figure(axes=[Axis(orientation='vertical', scale=LinearScale()), Axis(scale=LinearScale(max=70.0, min=-131.0))]…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"import numpy as np\n",
"from bqplot import pyplot as plt\n",
"import bqplot\n",
"\n",
"fig = plt.figure( title='Histogram')\n",
"np.random.seed(0)\n",
"hist = plt.hist(y, bins=25)\n",
"hist.scales['sample'].min = float(y.min())\n",
"hist.scales['sample'].max = float(y.max())\n",
"display(fig)\n",
"fig.layout.width = 'auto'\n",
"fig.layout.height = 'auto'\n",
"fig.layout.min_height = '300px' # so it shows nicely in the notebook\n",
"fig.layout.flex = '1'"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"grid_columns": 12,
"grid_rows": 6
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5fee6ee9af0a4dc7a557f8d16a5b7150",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Figure(axes=[Axis(scale=LinearScale()), Axis(orientation='vertical', scale=LinearScale())], fig_margin={'top':…"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"from bqplot import pyplot as plt\n",
"import bqplot\n",
"\n",
"fig = plt.figure( title='Line Chart')\n",
"np.random.seed(0)\n",
"n = 200\n",
"p = plt.plot(x, y)\n",
"fig"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"fig.layout.width = 'auto'\n",
"fig.layout.height = 'auto'\n",
"fig.layout.min_height = '300px' # so it shows nicely in the notebook\n",
"fig.layout.flex = '1'"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"brushintsel = bqplot.interacts.BrushIntervalSelector(scale=p.scales['x'])"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"def update_range(*args):\n",
" label_selected.value = \"Selected range {}\".format(brushintsel.selected)\n",
" mask = (x > brushintsel.selected[0]) & (x < brushintsel.selected[1])\n",
" hist.sample = y[mask]\n",
" \n",
"brushintsel.observe(update_range, 'selected')\n",
"fig.interaction = brushintsel"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Edit 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.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -0,0 +1,119 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Which multiplication table do you want to learn?\n",
"\n",
"In this example notebook we demonstrate how Voilà can render different Jupyter widgets using [GridspecLayout](https://ipywidgets.readthedocs.io/en/latest/examples/Layout%20Templates.html#Grid-layout)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "19dcc46af51049c9a9e26568b76aa789",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"GridspecLayout(children=(Dropdown(index=1, layout=Layout(grid_area='widget001'), options=(1, 2, 3, 4, 5, 6, 7,…"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ipywidgets import GridspecLayout, Button, BoundedIntText, Valid, Layout, Dropdown\n",
"\n",
"def create_expanded_button(description, button_style):\n",
" return Button(description=description, button_style=button_style, layout=Layout(height='auto', width='auto'))\n",
" \n",
"rows = 11\n",
"columns = 6\n",
"\n",
"gs = GridspecLayout(rows, columns)\n",
"\n",
"def on_result_change(change):\n",
" row = int(change[\"owner\"].layout.grid_row)\n",
" gs[row, 5].value = gs[0, 0].value * row == change[\"new\"]\n",
" \n",
"def on_multipler_change(change):\n",
" for i in range(1, rows):\n",
" gs[i, 0].description = str(change[\"new\"])\n",
" gs[i, 4].max = change[\"new\"] * 10\n",
" gs[i, 4].value = 1\n",
" gs[i, 4].step = change[\"new\"]\n",
" gs[i, 5].value = False\n",
"\n",
"gs[0, 0] = Dropdown(\n",
" options=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],\n",
" value=2,\n",
")\n",
"gs[0, 0].observe(on_multipler_change, names=\"value\")\n",
"multiplier = gs[0, 0].value\n",
"\n",
"for i in range(1, rows):\n",
" gs[i, 0] = create_expanded_button(str(multiplier), \"\")\n",
" gs[i, 1] = create_expanded_button(\"*\", \"\")\n",
" gs[i, 2] = create_expanded_button(str(i), \"info\")\n",
" gs[i, 3] = create_expanded_button(\"=\", \"\")\n",
"\n",
" gs[i, 4] = BoundedIntText(\n",
" min=0,\n",
" max=multiplier * 10,\n",
" layout=Layout(grid_row=str(i)),\n",
" value=1,\n",
" step=multiplier,\n",
" disabled=False\n",
" )\n",
"\n",
" gs[i, 5] = Valid(\n",
" value=False,\n",
" description='Valid!',\n",
" )\n",
"\n",
" gs[i, 4].observe(on_result_change, names='value')\n",
"\n",
"gs"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -0,0 +1,59 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "b6bf609f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"helloworld\n"
]
}
],
"source": [
"print('helloworld')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9b24b4df",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "1cc7f2dc",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -0,0 +1,76 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# So easy, *voilà*!\n",
"\n",
"In this example notebook, we demonstrate how Voilà can render notebooks making use of ipywidget's `@interact`."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "954b4c8acda94613bc8dde7e41ad5f9e",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"HBox(children=(VBox(children=(IntSlider(value=0), IntSlider(value=0))), Output()))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"from ipywidgets import HBox, VBox, IntSlider, interactive_output\n",
"from IPython.display import display\n",
"\n",
"a = IntSlider()\n",
"b = IntSlider()\n",
"\n",
"def f(a, b):\n",
" print(\"{} * {} = {}\".format(a, b, a * b))\n",
"\n",
"out = interactive_output(f, { \"a\": a, \"b\": b })\n",
"\n",
"display(HBox([VBox([a, b]), out]))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,66 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# So easy, *voilà*!\n",
"\n",
"In this example notebook, we demonstrate how Voilà can render custom Jupyter widgets such as [ipyvolume](https://github.com/maartenbreddels/ipyvolume). "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'collections' has no attribute 'Mapping'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn [2], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mipyvolume\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mipv\u001b[39;00m\n\u001b[1;32m 2\u001b[0m ipv\u001b[38;5;241m.\u001b[39mexamples\u001b[38;5;241m.\u001b[39mexample_ylm();\n",
"File \u001b[0;32m~/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/ipyvolume/__init__.py:4\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m__future__\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m absolute_import\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_version\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m __version__\n\u001b[0;32m----> 4\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m styles\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mwidgets\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m 6\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mtransferfunction\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n",
"File \u001b[0;32m~/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/ipyvolume/styles.py:56\u001b[0m\n\u001b[1;32m 47\u001b[0m light \u001b[38;5;241m=\u001b[39m create(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mlight\u001b[39m\u001b[38;5;124m\"\u001b[39m, \\\n\u001b[1;32m 48\u001b[0m {\n\u001b[1;32m 49\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbackground-color\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mwhite\u001b[39m\u001b[38;5;124m'\u001b[39m,\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 52\u001b[0m }\n\u001b[1;32m 53\u001b[0m })\n\u001b[1;32m 55\u001b[0m default \u001b[38;5;241m=\u001b[39m {}\n\u001b[0;32m---> 56\u001b[0m \u001b[43mutils\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdict_deep_update\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdefault\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43m_defaults\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 57\u001b[0m utils\u001b[38;5;241m.\u001b[39mdict_deep_update(default, light)\n\u001b[1;32m 59\u001b[0m dark \u001b[38;5;241m=\u001b[39m create(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdark\u001b[39m\u001b[38;5;124m\"\u001b[39m, \\\n\u001b[1;32m 60\u001b[0m {\n\u001b[1;32m 61\u001b[0m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mbackground-color\u001b[39m\u001b[38;5;124m'\u001b[39m: \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m#000001\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;66;03m# for some reason we cannot set it to black!?!\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 70\u001b[0m }\n\u001b[1;32m 71\u001b[0m })\n",
"File \u001b[0;32m~/.local/share/virtualenvs/app-4PlAip0Q/lib/python3.10/site-packages/ipyvolume/utils.py:19\u001b[0m, in \u001b[0;36mdict_deep_update\u001b[0;34m(d, u)\u001b[0m\n\u001b[1;32m 17\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mdict_deep_update\u001b[39m(d, u):\n\u001b[1;32m 18\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m u\u001b[38;5;241m.\u001b[39mitems():\n\u001b[0;32m---> 19\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(v, \u001b[43mcollections\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mMapping\u001b[49m):\n\u001b[1;32m 20\u001b[0m r \u001b[38;5;241m=\u001b[39m dict_deep_update(d\u001b[38;5;241m.\u001b[39mget(k, {}), v)\n\u001b[1;32m 21\u001b[0m d[k] \u001b[38;5;241m=\u001b[39m r\n",
"\u001b[0;31mAttributeError\u001b[0m: module 'collections' has no attribute 'Mapping'"
]
}
],
"source": [
"import ipyvolume as ipv\n",
"ipv.examples.example_ylm();"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"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.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -0,0 +1,289 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "913fbbd3",
"metadata": {},
"source": [
"# JSON"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "e23193bb",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "4c030553429b482b8a3a0d24347f745c",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(description='Output JSON', style=ButtonStyle())"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "31ece561ecab413f832f1d5033de4194",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from ipywidgets import Button, Output\n",
"from IPython import display\n",
"\n",
"button = Button(description='Output JSON')\n",
"output = Output()\n",
"obj = {\n",
" \"abcde\": 1234,\n",
" \"nested\": list(range(10))\n",
"}\n",
"\n",
"@output.capture()\n",
"def on_click(change):\n",
" display.display(display.JSON(obj))\n",
" \n",
" \n",
"button.on_click(on_click)\n",
"display.display(button)\n",
"output"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "690bd908",
"metadata": {},
"outputs": [
{
"data": {
"application/json": {
"abcde": 1234,
"nested": [
0,
1,
2,
3,
4,
5,
6,
7,
8,
9
]
},
"text/plain": [
"<IPython.core.display.JSON object>"
]
},
"execution_count": 4,
"metadata": {
"application/json": {
"expanded": false,
"root": "root"
}
},
"output_type": "execute_result"
}
],
"source": [
"display.JSON(obj)"
]
},
{
"cell_type": "markdown",
"id": "97caeade",
"metadata": {},
"source": [
"# Fasta"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "27bbbb6c",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "60c37cb6500547cf81751809d825af34",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(description='Output FASTA', style=ButtonStyle())"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0cfaf056ab234c0c8c4ff914d8334efb",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fasta_button = Button(description='Output FASTA')\n",
"fasta_output = Output()\n",
"\n",
"\n",
"def Fasta(data=''):\n",
" bundle = {}\n",
" bundle['application/vnd.fasta.fasta'] = data\n",
" bundle['text/plain'] = data\n",
" display.display(bundle, raw=True)\n",
" \n",
" \n",
"@fasta_output.capture()\n",
"def on_click(change):\n",
" Fasta(\"\"\">SEQUENCE_1\n",
"MTEITAAMVKELRESTGAGMMDCKNALSETNGDFDKAVQLLREKGLGKAAKKADRLAAEG\n",
"LVSVKVSDDFTIAAMRPSYLSYEDLDMTFVENEYKALVAELEKENEERRRLKDPNKPEHK\n",
"IPQFASRKQLSDAILKEAEEKIKEELKAQGKPEKIWDNIIPGKMNSFIADNSQLDSKLTL\n",
"MGQFYVMDDKKTVEQVIAEKEKEFGGKIKIVEFICFEVGEGLEKKTEDFAAEVAAQL\n",
">SEQUENCE_2\n",
"SATVSEINSETDFVAKNDQFIALTKDTTAHIQSNSLQSVEELHSSTINGVKFEEYLKSQI\n",
"ATIGENLVVRRFATLKAGANGVVNGYIHTNGRVGVVIAAACDSAEVASKSRDLLRQICMH\"\"\")\n",
"\n",
"\n",
"fasta_button.on_click(on_click)\n",
"display.display(fasta_button)\n",
"fasta_output"
]
},
{
"cell_type": "markdown",
"id": "a441bd16",
"metadata": {},
"source": [
"# GeoJSON"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "31371b2f",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "093f167a6c8642ca9e9bc1cdda6e73d1",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Button(description='Output GeoJSON', style=ButtonStyle())"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d78a22c950e34fd48c514bddad9c444b",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Output()"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from IPython.display import GeoJSON\n",
"\n",
"\n",
"geojson_button = Button(description='Output GeoJSON')\n",
"geojson_output = Output()\n",
"\n",
" \n",
"@geojson_output.capture()\n",
"def on_click(change):\n",
" obj = GeoJSON({\n",
" \"type\": \"Feature\",\n",
" \"geometry\": {\n",
" \"type\": \"Point\",\n",
" \"coordinates\": [-118.4563712, 34.0163116]\n",
" }\n",
" })\n",
" display.display(obj)\n",
" \n",
"\n",
"geojson_button.on_click(on_click)\n",
"display.display(geojson_button)\n",
"geojson_output"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9c0381b4",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "4099a46a",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -0,0 +1,69 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "ebaa184b-765f-4261-9c5c-285bbde8fad5",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "dfda01818965434d8417413b6c2020d5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(HBox(children=(Button(description='1', style=ButtonStyle()), Button(description='2', style=Butt…"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import ipywidgets as widgets\n",
"def generate(n):\n",
" widget = []\n",
" for i in range(n):\n",
" inner = []\n",
" for j in range(n):\n",
" inner.append(widgets.Button(description=f'{i*n+j+1}'))\n",
" widget.append(widgets.HBox(inner))\n",
"\n",
" return widgets.VBox(widget)\n",
"generate(20)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8b59589a-7c71-4b1a-896a-b1139cbcf70f",
"metadata": {},
"outputs": [],
"source": []
}
],
"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.10.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

View File

@@ -0,0 +1,107 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-18T12:06:29.243603Z",
"start_time": "2020-08-18T12:06:29.240780Z"
}
},
"outputs": [],
"source": [
"import os\n",
"from urllib.parse import parse_qs\n",
"import IPython.display"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-18T12:06:29.250356Z",
"start_time": "2020-08-18T12:06:29.246161Z"
}
},
"outputs": [],
"source": [
"query_string = os.environ.get('QUERY_STRING', '')\n",
"parameters = parse_qs(query_string)\n",
"print(\"query string parameters:\", parameters)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-18T12:06:29.258506Z",
"start_time": "2020-08-18T12:06:29.253815Z"
}
},
"outputs": [],
"source": [
"# parameters is a dict of lists\n",
"username = parameters.get('username', ['Kim'])[0]\n",
"print(f'Hi {username}')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"ExecuteTime": {
"end_time": "2020-08-18T12:06:29.275717Z",
"start_time": "2020-08-18T12:06:29.261315Z"
}
},
"outputs": [],
"source": [
"server = os.environ.get('SERVER_NAME', 'localhost') \n",
"url = \"http://\" + server\n",
"\n",
"port = os.environ.get('SERVER_PORT', '')\n",
"if port:\n",
" url += \":\" + port\n",
"\n",
"path = os.environ.get('SCRIPT_NAME', '')\n",
"url += path\n",
"\n",
" \n",
"IPython.display.HTML(data=f\"\"\"\n",
"<a href=\"{url}?username=Riley\">Link to myself as user Riley</a>\n",
"\"\"\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

View File

@@ -0,0 +1,135 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"hi\n"
]
}
],
"source": [
"print('hi')"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "583e6dc5fecc4802a205e91b768f0261",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"VBox(children=(FloatSlider(value=14.0, description='x'), FloatText(value=196.0, description='$x^2$', disabled=…"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import ipywidgets as widgets\n",
"slider = widgets.FloatSlider(description='x')\n",
"text = widgets.FloatText(disabled=True, description='$x^2$')\n",
"text.disabled\n",
"def compute(*ignore):\n",
" text.value = str(slider.value**2)\n",
"slider.observe(compute, 'value')\n",
"slider.value = 14\n",
"widgets.VBox([slider, text])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"voila\n"
]
}
],
"source": [
"print('voila')"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"1+2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"celltoolbar": "Slideshow",
"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.10.8"
},
"voila": {
"template": "reveal"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@@ -0,0 +1,161 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using Voilà with the C++ kernel and interactive widgets"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"#include <iostream>\n",
"#include <string>\n",
"\n",
"#include \"xwidgets/xoutput.hpp\"\n",
"\n",
"#include \"xleaflet/xmap.hpp\"\n",
"#include \"xleaflet/xdraw_control.hpp\"\n",
"#include \"xleaflet/xbasemaps.hpp\"\n",
"\n",
"namespace nl = nlohmann;"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Create map widget\n",
"auto water_color = xlf::basemap({\"OpenStreetMap\", \"France\"});\n",
"\n",
"auto map = xlf::map::initialize()\n",
" .layers({water_color})\n",
" .center({47, 363})\n",
" .zoom(5)\n",
" .finalize();\n",
"\n",
"map"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Create output widget to log draw events\n",
"xw::output out;\n",
"out"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Options for the draw control\n",
"nl::json polyline_options = {\n",
" {\"shapeOptions\", {\n",
" {\"color\", \"#6bc2e5\"},\n",
" {\"weight\", 8},\n",
" {\"opacity\", 1.0}\n",
" }}\n",
"};\n",
"\n",
"nl::json polygon_options = {\n",
" {\"shapeOptions\", {\n",
" {\"fillColor\", \"#6be5c3\"},\n",
" {\"color\", \"#6be5c3\"},\n",
" {\"fillOpacity\", 1.0}\n",
" }},\n",
" {\"drawError\", {\n",
" {\"color\", \"#dd253b\"},\n",
" {\"message\", \"Oups!\"}\n",
" }},\n",
" {\"allowIntersection\", false}\n",
"};\n",
"\n",
"nl::json circle_options = {\n",
" {\"shapeOptions\", {\n",
" {\"fillColor\", \"#efed69\"},\n",
" {\"fillOpacity\", 1.0},\n",
" {\"color\", \"#efed69\"}\n",
" }}\n",
"};\n",
"\n",
"nl::json rectangle_options = {\n",
" {\"shapeOptions\", {\n",
" {\"fillColor\", \"#fca45d\"},\n",
" {\"fillOpacity\", 1.0},\n",
" {\"color\", \"#fca45d\"}\n",
" }}\n",
"};"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Log last action\n",
"void print_draw_event(std::string action, nl::json geo_json)\n",
"{\n",
" // Capturing the stdout with the output widget \n",
" auto guard = out.guard();\n",
" std::cout << action << \" a \" \n",
" << geo_json[\"geometry\"][\"type\"]\n",
" << std::endl;\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"// Add the draw control and event logger\n",
"auto draw_control = xlf::draw_control::initialize()\n",
" .polyline(polyline_options)\n",
" .polygon(polygon_options)\n",
" .circle(circle_options)\n",
" .rectangle(rectangle_options)\n",
" .finalize();\n",
"\n",
"draw_control.on_draw(print_draw_event);\n",
"map.add_control(draw_control);"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "C++14",
"language": "C++14",
"name": "xcpp14"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "c++",
"version": "14"
}
},
"nbformat": 4,
"nbformat_minor": 4
}

View File

@@ -0,0 +1,27 @@
### to spin up dev environment
```
./start_docker.sh
// inside docker
./dev.sh
open host browser:
http://127.0.0.1:8888/?token=98ab80de026fe83fd8e03c8e344b31e7575ec4a084c59f21
```
### to develop
start from fresh python docker image
```
./start_docker.sh
./init.sh
```

View File

@@ -0,0 +1,18 @@
#!/usr/bin/env bash
set -ex
docker run -it \
-v $PWD:/app \
-w /app \
-v /var/run/docker.sock:/var/run/docker.sock \
-v ~/.ssh/id_rsa:/home/node/.ssh/id_rsa:ro \
-v ~/.ssh/known_host:/home/node/.ssh/known_hosts:ro \
-p 8888:8888 \
--rm \
python:3.10 \
bash
# -u 1000:1000 \
# -e XDG_CACHE_HOME=/app/.cache \