Write Multiple Shinylive Applications to Separate Directories
Source:R/writers.R
write_apps_to_dirs.RdTakes a list of parsed Shinylive applications and writes each to its own
numbered subdirectory. Creates consistently numbered directories with proper
padding (e.g., app_01, app_02) and preserves all application files and
metadata.
Arguments
- apps
List of parsed Shinylive applications. Each application should contain:
engine: Character string identifying the app type ("r"or"python")options: List of YAML-style options from the original code blockfiles: Named list of file definitions, each containing:name: Character string of the file namecontent: Character string of the file contenttype: Character string indicating the file type
- base_dir
Character string. Base directory where application subdirectories should be created. Will be created if it doesn't exist.
Value
No return value, called for its side effect of writing one application
subdirectory per app (plus a metadata file) under base_dir.
Details
The function performs these steps:
Creates the base directory if needed
Calculates proper padding for subdirectory numbers
For each application:
Creates a padded, numbered subdirectory (e.g.,
app_01,app_02)Writes all application files, preserving directory structure
Creates a metadata JSON file with engine and options info
See also
padding_width()for directory number padding calculationwrite_apps_to_quarto()for alternative Quarto output format
Examples
# Example apps list structure
apps <- list(
list(
engine = "r",
options = list(viewerHeight = 500),
files = list(
"app.R" = list(
name = "app.R",
content = "library(shiny)\n...",
type = "text"
)
)
),
list(
engine = "python",
options = list(),
files = list(
"app.py" = list(
name = "app.py",
content = "from shiny import App\n...",
type = "text"
)
)
)
)
write_apps_to_dirs(apps, file.path(tempdir(), "extracted_apps"))