簡體   English   中英

使用bind_shiny()渲染的ggvis圖不是反應性的

[英]ggvis plots rendered using bind_shiny() aren't reactive

我想我錯過了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)))

其中layeR_points用於繪制數據框中的數據,而layer_paths用於繪制直到maxValParam值的垂直線。

所以這個答案可能會有用。

看起來為了在ggvis()函數中引用你的input$maxValParam ,整個ggvis函數需要被包含在被動中。 公然扯掉上面的答案,你的看起來像是這樣的:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM