runcode | R Documentation |
Sometimes when developing a Shiny app, it's useful to be able to run some R
code on-demand. This construct provides your app with a text input where you
can enter any R code and run it immediately.
This can be useful for testing
and while developing an app locally, but it should not be included in
an app that is accessible to other people, as letting others run arbitrary R
code can open you up to security attacks.
To use this construct, you must add a call to runcode()
in the UI
of your app, and initialize shinyjs with a call to useShinyjs()
.
runcode(
code = "",
type = c("text", "textarea", "ace"),
width = NULL,
height = NULL,
ns = shiny::NS(NULL)
)
code |
The initial R code to show in the text input when the app loads |
type |
One of |
width |
The width of the editable code input (ignored when
|
height |
The height of the editable code input (ignored when
|
ns |
The |
You can only have one runcode
construct in your shiny app, do not
call it more than once in the UI.
useShinyjs
if (interactive()) {
library(shiny)
shinyApp(
ui = fluidPage(
useShinyjs(), # Set up shinyjs
runcode(code = "shinyjs::alert('Hello!')")
),
server = function(input, output) {}
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.