Shiny in R: How to properly use reactive, observe and renderUI? -


i have problem code. every time click button plot (built ggvis) showing vanishes immediately. since code long, following code reproduces problem. want reuse reactive data frame test0 in render function , guess causes problem. essential me. 3 steps (reactive, observe, render) same in code. appreciate help!

server.r

library(shiny) library(ggvis) library(dplyr)  data(mtcars)  shinyserver(function(input, output) {  test0 <- reactive({   df <- mtcars %>% select(mpg, wt)   (input$nextcounter + 1)*df })  observe({   df <- test0()   if (!is.null(df)) {      ggvis(df, x = ~wt, y = ~mpg) %>% bind_shiny("plotggvis")   } })  output$test1 <- renderui({   df <- test0()   ggvisoutput("plotggvis") })  }) 

ui.r

library(shiny)

shinyui(fluidpage(   sidebarlayout(   sidebarpanel(     actionbutton("nextcounter", "next")   ),    mainpanel(    uioutput("test1")  ) ) )) 

this 1 working me

library(shiny) library(ggvis) library(dplyr)   ui <- shinyui(fluidpage(  sidebarlayout( sidebarpanel(    actionbutton("nextcounter", "next") ),      mainpanel(     ggvisoutput("plotggvis")     )   )         ))  server <- shinyserver(function(input, output) {    data(mtcars)    test0 <- reactive({ df <- mtcars %>% select(mpg, wt) (input$nextcounter + 1)*df   })     my_graph <- reactive({     df <- test0()     ggvis(df, x = ~wt, y = ~mpg)   })    my_graph %>% bind_shiny("plotggvis")     })  })    shinyapp(ui = ui, server = server) 

Comments