Skip to content

Commit

Permalink
Various updates
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Oct 26, 2023
1 parent 68d4b30 commit ee6367d
Show file tree
Hide file tree
Showing 12 changed files with 1,430 additions and 176 deletions.
3 changes: 1 addition & 2 deletions doc/tutorials/00_Overview.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
"08. [**Scaling**: Async, threading, profiling and caching](08_Scalability.ipynb)\n",
"09. [**Server**: Effectively working with the server](09_Server.ipynb)\n",
"10. [**Multi-page Apps**: Different approaches for designing multi-page applications](10_MultiPage.ipynb)\n",
"11. [**Deep Linking**: Adding deep links and persistent sessions](11_Deep_Linking.ipynb)\n",
"12. [**Authentication and Authorization**: Configuring and effectively using OAuth](12_Authentication.ipynb)"
"11. [**Deep Linking**: Adding deep links and persistent sessions](11_Deep_Linking.ipynb)"
]
},
{
Expand Down
84 changes: 75 additions & 9 deletions doc/tutorials/01_Param.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,17 @@
"text_input.param.update(value='Updated!', width=85);"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b33371af-4c79-46ea-80e2-9763ef324933",
"metadata": {},
"outputs": [],
"source": [
"with text_input.param.update(value='Temporary'):\n",
" time.sleep(1)"
]
},
{
"cell_type": "markdown",
"id": "315ad0da-f3eb-4088-89be-da744c41eb0b",
Expand Down Expand Up @@ -228,6 +239,16 @@
"This also works when using it for other parameters, e.g. we can add a switch to toggle the visibility of some component:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6f09cdcc-f747-4f19-aa03-096f35f77833",
"metadata": {},
"outputs": [],
"source": [
"visible.param.value"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -293,7 +314,7 @@
"\n",
"text = pn.rx('**Hello {}!**').format(text_input)\n",
"\n",
"md = pn.pane.Markdown(text)\n",
"md = pn.pane.Markdown(text_i)\n",
"\n",
"pn.Row(text_input, md)"
]
Expand All @@ -317,6 +338,8 @@
"\n",
"df = pn.rx(pd.read_parquet('./windturbines.parq'))\n",
"\n",
"slider = pn.widgets.IntSlider(start=1, end=10)\n",
"\n",
"df.head(2)"
]
},
Expand Down Expand Up @@ -353,7 +376,7 @@
"\n",
"styled_df = df[cols].sample(nrows).style.apply(highlight_max, props=style.format(color=color), axis=0)\n",
"\n",
"styled_df"
"pn.pane.DataFrame(styled_df)"
]
},
{
Expand All @@ -371,7 +394,7 @@
"source": [
"### Exercise\n",
"\n",
"Write a small app where you can scale the `font-size` of a `Markdown` pane with another widget, e.g. an `IntSlider`. The `font-size` can be set using the `style` parameter.\n",
"Write a small app where you can scale the `font-size` of a `Markdown` pane with another widget, e.g. an `IntSlider`. The `font-size` can be set using the `styles` parameter.\n",
"\n",
":::{note} Hint\n",
":class: dropdown\n",
Expand All @@ -380,6 +403,20 @@
":::"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "efdc4c15-4130-42d7-8360-7e858e5c676c",
"metadata": {},
"outputs": [],
"source": [
"slider = pn.widgets.IntSlider(start=2, end=20, value=12, name='Font-size')\n",
"\n",
"md = pn.pane.Markdown('Some text')\n",
"\n",
"pn.Row(slider, md)"
]
},
{
"cell_type": "markdown",
"id": "73133325-134b-4190-b9ae-6dd8422e2957",
Expand Down Expand Up @@ -411,9 +448,9 @@
" \n",
" data = param.DataFrame(doc=\"Stores a DataFrame to explore\")\n",
" \n",
" page_size = param.Integer(default=10, doc=\"Number of rows per page.\", bounds=(1, None))\n",
" page_size = param.Integer(default=10, doc=\"Number of rows per page.\", bounds=(1, 20))\n",
" \n",
"explorer = DataExplorer(data=pd.read_parquet('./windturbines.parq'))"
"explorer = DataExplorer(data=pd.read_parquet('./windturbines.parq'), page_size=5)"
]
},
{
Expand All @@ -435,7 +472,7 @@
"metadata": {},
"outputs": [],
"source": [
"pn.Param(explorer.param)"
"pn.Param(explorer.param, widgets={'page_size': pn.widgets.IntInput})"
]
},
{
Expand Down Expand Up @@ -505,6 +542,26 @@
"Extend the `DataExplorer` class by adding parameters to control the `theme` and toggling the `show_index` option"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5f1d3e79-b34f-4769-9b1f-8c08eb4c863b",
"metadata": {},
"outputs": [],
"source": [
"pn.widgets.Tabulator.param"
]
},
{
"cell_type": "markdown",
"id": "687ec798-ef2e-480c-a508-429c69f8b2ff",
"metadata": {},
"source": [
"## Bug Report\n",
"\n",
"- Tabulator does not like `show_index=False` later toggled to `True`"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -513,18 +570,27 @@
"outputs": [],
"source": [
"class DataExplorer(Viewer):\n",
" \n",
"\n",
" data = param.DataFrame(doc=\"Stores a DataFrame to explore\")\n",
"\n",
" page_size = param.Integer(default=10, doc=\"Number of rows per page.\", bounds=(1, None))\n",
"\n",
" show_index = param.Boolean(default=True, doc=\"\")\n",
"\n",
" theme = param.Selector(objects=pn.widgets.Tabulator.param.theme.objects, default='bootstrap', doc=\"\")\n",
"\n",
" def __panel__(self):\n",
" return pn.Column(\n",
" pn.Row('Show Index', pn.widgets.Switch.from_param(self.param.show_index)),\n",
" self.param.theme,\n",
" pn.widgets.IntSlider.from_param(self.param.page_size, start=5, end=25, step=5),\n",
" pn.widgets.Tabulator(\n",
" self.param.data, page_size=self.param.page_size, sizing_mode='stretch_width'\n",
" self.param.data, page_size=self.param.page_size, show_index=self.param.show_index,\n",
" sizing_mode='stretch_width', theme=self.param.theme\n",
" )\n",
" )"
" )\n",
"\n",
"explorer = DataExplorer(data=pd.read_parquet('./windturbines.parq'))"
]
}
],
Expand Down
117 changes: 79 additions & 38 deletions doc/tutorials/02_Components.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,56 @@
"- text inputs: the `value` *Parameter* is only updated when the *Enter* key is pressed or the widget loses focus and the `value_input` *Parameter* is updated on every key press (more updates)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "09ab3e56-4ddf-4b0c-8911-57407dc96d2d",
"metadata": {},
"outputs": [],
"source": [
"pn.config.throttled = True"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3064f834-5169-409f-8d3d-2ee0fa187d76",
"metadata": {},
"outputs": [],
"source": [
"slider = pn.widgets.IntSlider(start=0, end=10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4fbdb08b-ba5c-4643-b0c9-80cc9c17a3cb",
"metadata": {},
"outputs": [],
"source": [
"text = pn.widgets.TextInput()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f5a8d26-a78a-4a30-9ad4-c8868bd08e5e",
"metadata": {},
"outputs": [],
"source": [
"text.value_input"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "da6ee1ad-3544-420b-9c07-cbd9b2c77e11",
"metadata": {},
"outputs": [],
"source": [
"slider.param.value_throttled"
]
},
{
"cell_type": "markdown",
"id": "ba0cf9d8-46d9-45d8-bb94-238b612ab639",
Expand Down Expand Up @@ -478,6 +528,16 @@
"png"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a1fd8057-bac9-4022-a0be-f65733c45398",
"metadata": {},
"outputs": [],
"source": [
"row = pn.Row('# Title')"
]
},
{
"cell_type": "markdown",
"id": "a35cc218-a092-483e-a694-fe1b4c5bab3a",
Expand Down Expand Up @@ -541,18 +601,6 @@
"p_md.object"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b9ebf421-63af-4939-9ae4-91621b5c2be7",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"p_md.object"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -619,25 +667,6 @@
"Indicators work well with asynchronous generators to quickly update their state without blocking."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8cf7ff5d-aab3-4f1d-b351-90819bc70a8c",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import asyncio\n",
"\n",
"async def moving_progress():\n",
" for i in range(11):\n",
" await asyncio.sleep(0.1)\n",
" yield pn.indicators.Progress(value=i*10)\n",
"\n",
"pn.panel(moving_progress)"
]
},
{
"cell_type": "markdown",
"id": "3cdeb86c-535b-4136-b612-2fd344ca771f",
Expand Down Expand Up @@ -818,7 +847,7 @@
},
"outputs": [],
"source": [
"tabs = pn.Tabs('Some text')\n",
"tabs = pn.Tabs(('Text', 'Some text'))\n",
"tabs"
]
},
Expand Down Expand Up @@ -870,7 +899,9 @@
"source": [
"import holoviews as hv\n",
"\n",
"hv.extension('bokeh')"
"hv.extension('bokeh')\n",
"\n",
"pn.extension('gridstack')"
]
},
{
Expand All @@ -882,8 +913,7 @@
},
"outputs": [],
"source": [
"gspec = pn.GridSpec(sizing_mode='stretch_width', height=500)\n",
"\n",
"gspec = pn.GridStack(sizing_mode='stretch_width', height=500)\n",
"gspec[0, :3] = pn.Spacer(styles=dict(background='#FF0000'))\n",
"gspec[1:3, 0] = pn.Spacer(styles=dict(background='#0000FF'))\n",
"gspec[1:3, 1:3] = hv.Scatter([0, 1, 0]).opts(shared_axes=False)\n",
Expand Down Expand Up @@ -942,6 +972,17 @@
"p_md"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "cc7f0ce0-bba4-4701-82cb-e5fb3a1fe497",
"metadata": {},
"outputs": [],
"source": [
"pn.config.loading_spinner = 'petal'\n",
"pn.config.loading_color = 'red'"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -992,7 +1033,7 @@
},
"outputs": [],
"source": [
"w_text.visible = False"
"w_text.visible = True"
]
},
{
Expand Down Expand Up @@ -1071,7 +1112,7 @@
},
"outputs": [],
"source": [
"pn.widgets.Button(name='Click', margin=25)"
"pn.widgets.Button(name='Click', margin=(25, 0, 0, 0))"
]
},
{
Expand Down Expand Up @@ -1101,7 +1142,7 @@
"source": [
"pn.Row(\n",
" pn.widgets.IntSlider(),\n",
" pn.widgets.IntSlider(align='center'),\n",
" pn.widgets.IntSlider(align=('center', 'start')),\n",
" height=100,\n",
" styles={'background': 'lightgrey'},\n",
")"
Expand Down
Loading

0 comments on commit ee6367d

Please sign in to comment.