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

daj*_*daj 3 r reactive-programming shiny ggvis

我想我错过了ggvis + shiny的一些基本方面.

在教程之后,使用一系列%>%管道在server.R中构建绘图,以bind_shiny结尾,该绘图将绘图与可在ui.R中引用的标识符相关联.

我没有得到的是,绘图本身并不像renderTable(),renderText()或reactive()中的代码那样具有反应性.因此,如果我想在定义绘图时引用输入参数(如输入$ 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)))
Run Code Online (Sandbox Code Playgroud)

其中layeR_points用于绘制数据框中的数据,而layer_paths用于绘制直到maxValParam值的垂直线.

col*_*d77 6

所以这个答案可能会有用.

看起来为了引用你的input$maxValParam内部ggvis()函数,整个ggvis函数需要被包含在被动中.公然扯掉上面的答案,你的看起来像是这样的:

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