Should make sure that bind_shiny doesn't leave observers floating around
bind_shiny can potentially leave observers floating around each time the user selects a new value:
server <- function(input, output) {
observe({
xvar <- if (is.null(input$column)) "wt" else input$column
xprop <- prop("x", as.name(xvar))
mtcars %>% ggvis(xprop, ~mpg) %>% layer_points() %>% bind_shiny("plot1")
})
}
ui <- fluidPage(
selectInput("column", "Column for x", c("wt", "mpg", "disp", "hp")),
ggvisOutput("plot1")
)
shinyApp(server = server, ui = ui)
On the other hand, this would not, because bind_shiny is run just once:
server <- function(input, output) {
reactive({
xvar <- if (is.null(input$column)) "wt" else input$column
xprop <- prop("x", as.name(xvar))
mtcars %>% ggvis(xprop, ~mpg) %>% layer_points()
}) %>% bind_shiny("plot1")
}
ui <- fluidPage(
selectInput("column", "Column for x", c("wt", "mpg", "disp", "hp")),
ggvisOutput("plot1")
)
shinyApp(server = server, ui = ui)
We should make sure that either (A) bind_shiny is run only outside of a reactive, or (B) when bind_shiny is run with a name that has already been bound, all the previously-created observers are suspended.
This is related to #165.
Can't we make observers suspend themselves on gc? Or do they need to be suspect before they get collected?
On Tuesday, September 9, 2014, Winston Chang [email protected] wrote:
bind_shiny can potentially leave observers floating around each time the user selects a new value:
server <- function(input, output) { observe({ xvar <- if (is.null(input$column)) "wt" else input$column xprop <- prop("x", as.name(xvar)) mtcars %>% ggvis(xprop, ~mpg) %>% layer_points() %>% bind_shiny("plot1") })}
ui <- fluidPage( selectInput("column", "Column for x", c("wt", "mpg", "disp", "hp")), ggvisOutput("plot1"))
shinyApp(server = server, ui = ui)
On the other hand, this would not, because bind_shiny is run just once:
server <- function(input, output) { reactive({ xvar <- if (is.null(input$column)) "wt" else input$column xprop <- prop("x", as.name(xvar)) mtcars %>% ggvis(xprop, ~mpg) %>% layer_points() }) %>% bind_shiny("plot1")}
ui <- fluidPage( selectInput("column", "Column for x", c("wt", "mpg", "disp", "hp")), ggvisOutput("plot1"))
shinyApp(server = server, ui = ui)
We should make sure that either (A) bind_shiny is run only outside of a reactive, or (B) when bind_shiny is run with a name that has already been bound, all the previously-created observers are suspended.
— Reply to this email directly or view it on GitHub https://github.com/rstudio/ggvis/issues/254.
http://had.co.nz/
Observers need to be suspended before they're gc'ed. So we would need a way to suspend them when another bind_shiny is called with the same name.
Is there any work around that could be used in the meantime?