Skip to contents

Unified function to create Shinylive projects for either R or Python. This provides a consistent interface similar to webr_repl_project().

Usage

shinylive_project(
  files,
  engine,
  mode = "editor",
  header = TRUE,
  base_url = NULL
)

Arguments

files

Named list where names are filenames and values are file content as character strings

engine

Engine to use: "r" for R Shiny or "python" for Python Shiny

mode

Shinylive mode: "editor" (show code editor) or "app" (show app only)

header

Logical. Whether to show header in app mode (default: TRUE)

base_url

Custom Shinylive base URL. If NULL, uses default Shinylive URL

Value

shinylive_project object containing the Shinylive URL and metadata

Examples

# R Shiny project
r_files <- list(
  "app.R" = '
library(shiny)
source("utils.R")
ui <- fluidPage(titlePanel("My App"))
server <- function(input, output) {}
shinyApp(ui, server)
  ',
  "utils.R" = "helper_function <- function(x) { x * 2 }"
)

r_project <- shinylive_project(r_files, engine = "r", mode = "editor")
print(r_project)
#> 
#> ── Shinylive R Project ──
#> 
#> <https://shinylive.io/r/editor/#code=NobwRAdghgtgpmAXGKAHVA6ASmANGAYwHsIAXOMpMAHQgBsBLAIwCcoWBPACgGcALBhA4BKWjyIBXFgThdqYCaQZ0e2eaIgSGAAgA8AWm0AzOloAmABSgBzWUtJ04ViHDpywAWQ7aAgunUaPHAsAG7BeoZGEhAESiRcgqiKuNqSpEmkwtogAL5iAkJ+qFxaKUGhwRra2nhgpByoCMjkAB6kYDm44NDwVIrKqjj4xGQU7ch8ro0sAPpRMXEQEcbRsQzxLVkg2i3aAFTaAEzaObX1jVSt7TkAukA>
#> 
#> Files (2):
#> app.R
#> utils.R
#> 
#> Engine: "R"
#> Mode: "editor"

# Python Shiny project
py_files <- list(
  "app.py" = '
from shiny import App, ui
from utils import process_data
app = App(ui.page_fluid("Hello"), None)
  ',
  "utils.py" = "def process_data(x): return x"
)

py_project <- shinylive_project(py_files, engine = "python", mode = "app")