Description Usage Arguments Value Examples
Takes in a shiny server function, searches working directory for
app.R
and global.R
files, and reconstructs an independent R
script from the server components.
1 2 3 4 |
server |
the server function to generate an R script for |
... |
names of output names for which to build code |
dots |
optionally pass ellipses names of outputs as list |
call_outputs |
whether calls to the specified outputs should be appended at the end of the script |
initialize_params |
whether to add code to instantiate server function arguments in the generated script. this is generally useful for the top level call, but not for subsequent nested modules. |
keep_returns |
whether to prune return statements if they arent' needed for generated specified outputs. this is generally useful in situations where a specific output is desired, but unwanted when generated compelete nested module code. |
flatten_outputs |
whether a singular output should be collapsed into parent script |
files |
the filepaths to search for available shiny globally scoped code |
envir |
the environment in which to search for arguments originally passed to the server function. A construction of those arguments as they exist in the current state will attempt to be built into the generated script. |
session |
the active shiny session, defaults to the value of the variable by the same name in the parent environment. |
a script representing the current state of the shiny app, allowing for independent reproduction of the shiny outputs.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | ## Not run:
## Shiny Example (app.R contents)
try(setwd(dirname(rstudioapi::getActiveDocumentContext()$path)), silent = TRUE) # R Studio
try(setwd(dirname(dirname(parent.frame(2)$ofile))), silent = TRUE) # running as a script
library(shiny)
my_data <- datasets::mtcars
# additional code before shinyApp call will be captured if in app.R
ui <- fluidPage(
selectInput('x', 'x axis', choices = names(my_data)),
selectInput('y', 'y axis', choices = names(my_data)),
plotOutput('plot'),
verbatimTextOutput('code')
)
srv <- function(input, output, session) {
output$plot <- renderPlot({
plot(x = my_data[[input$x]],
y = my_data[[input$y]])
})
output$code <- renderPrint({
cat(get_code(srv, 'plot'))
})
}
shinyApp(ui, srv)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.