1+ {
2+ "cells": [
3+ {
4+ "cell_type": "markdown",
5+ "metadata": {},
6+ "source": [
7+ "---\n",
8+ "title: \"shiny in Python introduction\"\n",
9+ "author: \"Tony Duan\"\n",
10+ "execute:\n",
11+ " warning: false\n",
12+ " error: false\n",
13+ "\n",
14+ " \n",
15+ "format:\n",
16+ " html:\n",
17+ " toc: true\n",
18+ " toc-location: right\n",
19+ " code-fold: show\n",
20+ " code-tools: true\n",
21+ " \n",
22+ " code-block-bg: true\n",
23+ " code-block-border-left: \"#31BAE9\"\n",
24+ " code-copy: true\n",
25+ "\n",
26+ "\n",
27+ "filters:\n",
28+ " - shinylive\n",
29+ " \n",
30+ "---\n"
31+ ],
32+ "id": "47caccc4"
33+ },
34+ {
35+ "cell_type": "code",
36+ "metadata": {},
37+ "source": [
38+ "#| eval: false\n",
39+ "pip install shiny"
40+ ],
41+ "id": "b90c813b",
42+ "execution_count": null,
43+ "outputs": []
44+ },
45+ {
46+ "cell_type": "markdown",
47+ "metadata": {},
48+ "source": [
49+ "# if using shinylive(shiny without server) then install extension in your Quarto project"
50+ ],
51+ "id": "206fc899"
52+ },
53+ {
54+ "cell_type": "code",
55+ "metadata": {},
56+ "source": [
57+ "#| eval: false\n",
58+ "quarto add quarto-ext/shinylive"
59+ ],
60+ "id": "bce7b442",
61+ "execution_count": null,
62+ "outputs": []
63+ },
64+ {
65+ "cell_type": "markdown",
66+ "metadata": {},
67+ "source": [
68+ "# Add filters in YAML header\n",
69+ "\n",
70+ "````\n",
71+ "---\n",
72+ "\n",
73+ "filters:\n",
74+ " - shinylive\n",
75+ " \n",
76+ "---\n",
77+ "````\n",
78+ "\n",
79+ "# Shiny code\n",
80+ "\n",
81+ "````\n",
82+ "\n",
83+ "```{shinylive-python}\n",
84+ "#| standalone: true\n",
85+ "\n",
86+ "from shiny import *\n",
87+ "\n",
88+ "app_ui = ui.page_fluid(\n",
89+ " ui.input_slider(\"n\", \"N\", 0, 100, 40),\n",
90+ " ui.output_text_verbatim(\"txt\"),\n",
91+ ")\n",
92+ "\n",
93+ "\n",
94+ "def server(input, output, session):\n",
95+ " @output\n",
96+ " @render.text\n",
97+ " def txt():\n",
98+ " return f\"The value of n*2 is {input.n() * 2}\"\n",
99+ "\n",
100+ "app = App(app_ui, server)\n",
101+ "```\n",
102+ "\n",
103+ "````\n",
104+ "\n",
105+ "```{shinylive-python}\n",
106+ "#| standalone: true\n",
107+ "\n",
108+ "from shiny import *\n",
109+ "\n",
110+ "app_ui = ui.page_fluid(\n",
111+ " ui.input_slider(\"n\", \"N\", 0, 100, 40),\n",
112+ " ui.output_text_verbatim(\"txt\"),\n",
113+ ")\n",
114+ "\n",
115+ "\n",
116+ "def server(input, output, session):\n",
117+ " @output\n",
118+ " @render.text\n",
119+ " def txt():\n",
120+ " return f\"The value of n*2 is {input.n() * 2}\"\n",
121+ "\n",
122+ "app = App(app_ui, server)\n",
123+ "```\n",
124+ "\n",
125+ "\n",
126+ "\n",
127+ "\n",
128+ "# Reference\n",
129+ "\n",
130+ "https://shiny.posit.co/py/get-started/shinylive.html\n"
131+ ],
132+ "id": "edd6acc0"
133+ }
134+ ],
135+ "metadata": {
136+ "kernelspec": {
137+ "name": "python3",
138+ "language": "python",
139+ "display_name": "Python 3 (ipykernel)",
140+ "path": "/Library/Frameworks/Python.framework/Versions/3.13/share/jupyter/kernels/python3"
141+ }
142+ },
143+ "nbformat": 4,
144+ "nbformat_minor": 5
145+ }
0 commit comments