Skip to content

Commit

Permalink
Fix #1193: adjust the environment in which R code chunks in Shiny Rmd…
Browse files Browse the repository at this point in the history
… are evaluated

The environment should not be simply render_args$envir (which defaults to parent.frame() in render()), because Shiny's input/output/session variables are not available in this environment. We have to create a new environment with the environment of Shiny's server function environment being its parent, and render_args$envir being its grandparent environment.

All previous relevant cases #1162, #619, and #1124 have been tested.

Also closes #1194.
  • Loading branch information
yihui committed Nov 10, 2017
1 parent be99f85 commit 67eaa7a
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions R/shiny.R
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ rmarkdown_shiny_server <- function(dir, file, encoding, auto_reload, render_args
else
function() { file }

envir_global <- render_args[['envir']]
envir_server <- list2env(list(
input = input, output = output, session = session
), parent = envir_global)
render_args$envir <- new.env(parent = envir_server)

# when the file loads (or is changed), render to a temporary file, and
# read the contents into a reactive value
doc <- shiny::reactive({
Expand Down

0 comments on commit 67eaa7a

Please sign in to comment.