diff --git a/export_template/edit/index.html b/export_template/edit/index.html index b723545b..c0fc9d35 100644 --- a/export_template/edit/index.html +++ b/export_template/edit/index.html @@ -1,34 +1,11 @@ - - + + - - - Shiny examples browser - - - - Redirect to editable app + - - - - -
- + diff --git a/export_template/index.html b/export_template/index.html index a50111ea..da340575 100644 --- a/export_template/index.html +++ b/export_template/index.html @@ -1,28 +1,30 @@ - + - Shiny App + {{#title}} + {{.}} + {{/title}} + {{{ include_in_head }}} + {{{ include_before_body }}}
+ {{{ include_after_body }}} diff --git a/src/Components/App.tsx b/src/Components/App.tsx index 326358cf..5f4e6773 100644 --- a/src/Components/App.tsx +++ b/src/Components/App.tsx @@ -75,6 +75,15 @@ export type AppMode = | "editor-cell" | "viewer"; +const AppModes = [ + "examples-editor-terminal-viewer", + "editor-terminal-viewer", + "editor-terminal", + "editor-viewer", + "editor-cell", + "viewer", +]; + type AppOptions = { // An optional set of files to start with. startFiles?: FileContentJson[] | FileContent[]; @@ -557,6 +566,40 @@ export function App({ } } +// This function helps launch apps exported with the shinylive Python and R +// packages and is used by `export_template/index.html`. +export async function runExportedApp({ + id, + appEngine, + relPath = "", +}: { + id: string; + appEngine: AppEngine; + relPath: string; +}) { + const response = await fetch("./app.json"); + if (!response.ok) { + throw new Error("HTTP error loading app.json: " + response.status); + } + const appFiles = await response.json(); + + const appRoot = document.getElementById(id); + if (!appRoot) { + throw new Error(`Could not find app root element with id "${id}"`); + } + + // Get `appMode` from the URL query string + const urlParams = new URLSearchParams(window.location.search); + let appMode = urlParams.get("mode") ?? "viewer"; + + if (!AppModes.includes(appMode)) { + console.warn(`[shinylive] Unrecognized app mode: ${appMode}`); + appMode = "viewer"; + } + + runApp(appRoot, appMode as AppMode, { startFiles: appFiles }, appEngine); +} + // The exported function that can be used for embedding into a web page. // // Note: When `allowCodeUrl`, `allowGistUrl`, and `allowExampleUrl` are enabled,