Parses the content of a Shinylive code block, extracting YAML-style options, file definitions, and content. Handles both single-file and multi-file applications for R and Python.
Value
A list with three components:
engine
: Character string indicating the application type ("r"
or"python"
)options
: List of parsed YAML-style options from block headersfiles
: Named list of file definitions, where each file contains:name
: Character string of the file namecontent
: Character string of the file contenttype
: Character string indicating the file type (defaults to `"text"“)
Code Block Structure
The code block can contain several types of lines:
YAML-style options: Lines starting with `'#|'“
File markers: Lines starting with
'## file:'
Type markers: Lines starting with
'## type:'
Content: All other non-empty lines
For single-file applications with no explicit file marker, the content is automatically placed in:
"app.R"
for R applications"app.py"
for Python applications
See also
parse_yaml_options()
for YAML-style option parsingfind_shinylive_code()
for extracting code blocks from HTML
Examples
if (FALSE) { # \dontrun{
# Single-file R application
code <- '
#| viewerHeight: 500
library(shiny)
ui <- fluidPage()
server <- function(input, output) {}
shinyApp(ui, server)
'
result1 <- parse_code_block(code, "r")
# Multi-file Python application
code <- '
#| fullWidth: true
## file: app.py
from shiny import App, ui
app = App(app_ui)
## file: requirements.txt
## type: text
shiny>=0.5.0
'
result2 <- parse_code_block(code, "python")
} # }