From bcc9f382fea65584090ae9b6112dd6d67dc28510 Mon Sep 17 00:00:00 2001 From: Dean Attali Date: Sat, 15 Oct 2016 01:11:42 -0700 Subject: [PATCH] add `includeShinyjs` param to `runcode` construct, to make it a bit easier to call --- DESCRIPTION | 2 +- R/runcode.R | 16 +++++++++++++--- man/runcode.Rd | 15 ++++++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 75c9bd3..a14ec36 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: shinyjs Title: Easily Improve the User Experience of Your Shiny Apps in Seconds -Version: 0.7.9003 +Version: 0.7.9004 Authors@R: person("Dean", "Attali", email = "daattali@gmail.com", role = c("aut", "cre")) Description: Perform common useful JavaScript operations in Shiny apps that will diff --git a/R/runcode.R b/R/runcode.R index 4a42159..8019b18 100644 --- a/R/runcode.R +++ b/R/runcode.R @@ -4,12 +4,16 @@ #' code on-demand. This construct provides your app with a text input where you #' can enter any R code and run it immediately.\cr\cr #' This can be useful for testing -#' and while developing an app locally, but it \emph{should not be included in +#' and while developing an app locally, but it \strong{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.\cr\cr #' To use this construct, you must add a call to \code{runcodeUI()} in the UI #' of your app, and a call to \code{runcodeServer()} in the server function. You -#' also need to initialize shinyjs with a call to \code{useShinyjs()}. +#' also need to initialize shinyjs with a call to \code{useShinyjs()} in the UI. +#' +#' @note You can only have one \code{runcode} construct in your shiny app. +#' Calling this function multiple times within the same app will result in +#' unpredictable behaviour. #' #' @param code The initial R code to show in the text input when the app loads #' @param type One of \code{"text"} (default) or \code{"textarea"}. When using @@ -20,6 +24,9 @@ #' @param width The width of the text or textarea input #' @param height The height of the textarea input (only applicable when #' \code{type="textarea"}) +#' @param includeShinyjs Set this to \code{TRUE} only if your app does not have +#' a call to \code{useShinyjs()}. If you are already calling \code{useShinyjs()} +#' in your app, do not use this parameter. #' @seealso \code{\link[shinyjs]{useShinyjs}} #' @examples #' if (interactive()) { @@ -42,11 +49,14 @@ runcodeUI <- function(code = "", type = c("text", "textarea"), width = NULL, - height = NULL) { + height = NULL, + includeShinyjs = FALSE) { type <- match.arg(type) placeholder <- "Enter R code" shiny::singleton(shiny::tagList( + if (includeShinyjs) + useShinyjs(), if(type == "text") shiny::textInput( "runcode_expr", label = NULL, value = code, diff --git a/man/runcode.Rd b/man/runcode.Rd index c7777c7..61fad48 100644 --- a/man/runcode.Rd +++ b/man/runcode.Rd @@ -7,7 +7,7 @@ \title{Construct to let you run arbitrary R code live in a Shiny app} \usage{ runcodeUI(code = "", type = c("text", "textarea"), width = NULL, - height = NULL) + height = NULL, includeShinyjs = FALSE) runcodeServer() } @@ -24,18 +24,27 @@ a single line by appending each R expression with a semicolon.} \item{height}{The height of the textarea input (only applicable when \code{type="textarea"})} + +\item{includeShinyjs}{Set this to \code{TRUE} only if your app does not have +a call to \code{useShinyjs()}. If you are already calling \code{useShinyjs()} +in your app, do not use this parameter.} } \description{ 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.\cr\cr This can be useful for testing -and while developing an app locally, but it \emph{should not be included in +and while developing an app locally, but it \strong{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.\cr\cr To use this construct, you must add a call to \code{runcodeUI()} in the UI of your app, and a call to \code{runcodeServer()} in the server function. You -also need to initialize shinyjs with a call to \code{useShinyjs()}. +also need to initialize shinyjs with a call to \code{useShinyjs()} in the UI. +} +\note{ +You can only have one \code{runcode} construct in your shiny app. +Calling this function multiple times within the same app will result in +unpredictable behaviour. } \examples{ if (interactive()) {