使用 bind_shiny() 渲染的 ggvis 图不是反应式的

ggvis plots rendered using bind_shiny() aren't reactive

我想我缺少 ggvis + shiny 的一些基本方面。

按照教程,使用一系列 %>% 管道在 server.R 中构建地块,以 bind_shiny 结尾,它将地块与可在 [= 中引用的标识符相关联25=]

但我不明白的是,情节本身并不像 renderTable()、renderText() 或 reactive() 中的代码那样具有反应性。因此,如果我想在定义绘图时引用像 input$x 这样的输入参数,它将不起作用,我会收到一条错误消息 "Operation not allowed without an active reactive context. (You tried to do something that can only be done from inside a reactive expression or observer.)".

例如,如果 'input' 是 shinyServer 函数的输入参数,我的绘图可能如下所示:

dataframe %>% ggvis(~ aval, ~ bval) %>% layer_points %>% layer_paths(x = ~xv, y = ~ yv, data = data.frame(xv = c(0, 0), yv = c(0, input$maxValParam)))

其中 layeR_points 用于绘制数据框中的数据,layer_paths 用于绘制一条垂直线,直至 maxValParam 值。

所以 this answer 可能会有用。

看起来为了在 ggvis() 函数中引用您的 input$maxValParam,整个 ggvis 函数需要包装在一个 reactive. 公然抄袭上述答案,您的答案可能类似于:

reactive({
  dataframe %>% 
      ggvis() #rest of plotting code %>% 
      add_axis("x", title = input$maxValParam)
}) %>% bind_shiny("plot")