From c6260fbe376ecc89f98da1a7654f00e5bf5e5536 Mon Sep 17 00:00:00 2001 From: David Beal Date: Mon, 11 Aug 2025 16:37:41 +0200 Subject: [PATCH 1/3] example: shiny --- examples/frameworks/shiny/main.py | 86 +++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 examples/frameworks/shiny/main.py diff --git a/examples/frameworks/shiny/main.py b/examples/frameworks/shiny/main.py new file mode 100644 index 00000000000..df9d9dbd3ea --- /dev/null +++ b/examples/frameworks/shiny/main.py @@ -0,0 +1,86 @@ +# /// script +# requires-python = ">=3.12" +# dependencies = [ +# "shiny", +# "marimo", +# "vega-datasets==0.9.0", +# ] +# /// +from shiny import App, render, ui +from htmltools import HTML +import marimo +import os +from starlette.middleware.wsgi import WSGIMiddleware +from starlette.applications import Starlette +from starlette.routing import Mount, Route +from starlette.responses import RedirectResponse + + +ui_dir = os.path.join(os.path.dirname(__file__), "..", "..", "ui") +templates_dir = os.path.join(os.path.dirname(__file__), "templates") + +marimo_app = marimo.create_asgi_app() +app_names: list[str] = [] + +for filename in sorted(os.listdir(ui_dir)): + if filename.endswith(".py"): + app_name = os.path.splitext(filename)[0] + app_path = os.path.join(ui_dir, filename) + marimo_app = marimo_app.with_app(path=f"/{app_name}", root=app_path) + app_names.append(app_name) + +shiny_ui = ui.page_fluid(ui.output_ui("_html")) + + +def shiny_server(input, output, session): + @render.text + def _html(): + subdiv = [] + for name in app_names: + subdiv.append( + f""" +
+ +
+

{name}

+

Click to open app

+
+
+
+ """ + ) + head = """ + +