r - Shiny - Are reactive environments possible? -
right now, have expression looks this:
you can run directly app.r
file. it's standalone, , demonstrates effect want.
library(shiny) rval <- reactivevalues() rval$var <- new.env() rval$flag <- false isolate({ rval$var$a <- 1 rval$var$b <- "hello" rval$var$c <- c(1.2, 12.3, 123.0) rval$var$d <- list(1,2,"a") }) ui <- navbarpage('reactivetest', tabpanel('analysis', fluidrow( actionbutton("addvar", "add null var"), tableoutput('vars') ) ) ) core_variable_table <- eventreactive(rval$flag == true, { print(ls(rval$var)) rval$flag <- false df <- data.frame(ls(rval$var), sapply(ls(rval$var), function(x){ class(get(x, envir = rval$var))}), sapply(ls(rval$var), function(x){ y <- head(get(x, envir = rval$var)) if(is.null(y)) { return("null") } else { return(tostring(y)) } }) ) rownames(df) <- seq(1, length(ls(rval$var))) colnames(df) <- c('name', 'type', 'content') return(df) }) dothis <- function(name, data) { observe({ assign(x=name, value=data, envir=rval$var) }) isolate({ rval$flag <- true }) } server <- function(input, output, session) { output$vars <- rendertable({ return(core_variable_table()) }) observeevent(input$addvar, { rval$update dothis("gecko", null) }) } shinyapp(ui, server)
as can see, i'm trying bind entire environment variable, , want changes occur if variable in environment modified. how might bind reactivity of shiny outputs entire environment or variables in environment without having use terrible flag method?
edit: note starts come apart once start having more 1 function trigger. don't wish have flip 5 flags 1 function--shiny should have way of doing things this...
the fix i've come instead generate view of environment based on flag or integer increment. example, if modify of variables in environment, manually change reactive variable signals output of application needs update.
Comments
Post a Comment