Write Standalone Shinylive Application Files from JSON Data
Source:R/writers.R
write_standalone_shinylive_app.RdExtracts files from parsed Shinylive app.json data and writes them to a
specified directory. Creates a standalone application object containing
metadata and commands for running the application.
Arguments
- json_data
List. Parsed JSON data from a Shinylive
app.jsonfile. Each element should be a list containing:name: Character string of the file namecontent: Character string of the file contenttype: Character string indicating the file type
- source_url
Character string. The original URL from which the
app.jsonwas downloaded. Used for reference and provenance tracking in the returned object.- output_dir
Character string. Directory where application files should be extracted. Defaults to
"converted_shiny_app". Will be created if it doesn't exist. Existing files in this directory may be overwritten.
Value
An object of class "standalone_shinylive_app" containing:
files: List of extracted files and their metadataoutput_dir: Path to the directory containing extracted filessource_url: Original URL of the application
Details
The function performs these steps:
Creates the output directory if it doesn't exist
Iterates through each file in the JSON data
Writes each file to the output directory, preserving names
Creates a standalone application object with metadata
File paths are created relative to the output directory. Parent directories in file paths will be created as needed.
See also
create_standalone_shinylive_app()for object creationvalidate_app_json()for JSON data validation
Examples
# Example JSON data structure
json_data <- list(
list(
name = "app.R",
content = "library(shiny)\nui <- fluidPage()\n...",
type = "text"
),
list(
name = "data.csv",
content = "col1,col2\n1,2\n3,4",
type = "text"
)
)
app <- write_standalone_shinylive_app(
json_data,
"https://example.com/app.json",
"my_app"
)