
Last chance! 50% off unlimited learning
Sale ends in
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 runcodeUI()
in the UI
of your app, and a call to runcodeServer()
in the server function. You
also need to initialize shinyjs with a call to useShinyjs()
in the UI.
runcodeUI(code = "", type = c("text", "textarea", "ace"), width = NULL,
height = NULL, includeShinyjs = FALSE)runcodeServer()
The initial R code to show in the text input when the app loads
One of "text"
(default), "textarea"
, or "ace"
.
When using a text input, the R code will be limited to be typed within a single line,
and is the recommended option. Textarea should be used if you want to write
long multi-line R code. Note that you can run multiple expressions even in
a single line by appending each R expression with a semicolon.
Use of the "ace"
option requires the shinyAce
package.
The width of the editable code input (ignored when
type="ace"
)
The height of the editable code input (ignored when
type="text"
)
Set this to TRUE
only if your app does not have
a call to useShinyjs()
. If you are already calling useShinyjs()
in your app, do not use this parameter.
# NOT RUN {
if (interactive()) {
library(shiny)
shinyApp(
ui = fluidPage(
useShinyjs(), # Set up shinyjs
runcodeUI(code = "shinyjs::alert('Hello!')")
),
server = function(input, output) {
runcodeServer()
}
)
}
# }
Run the code above in your browser using DataLab