【问题标题】:Why is plotOutput still brushable when it failed to validate?为什么 plotOutput 在验证失败时仍然可以刷?
【发布时间】:2018-07-27 19:52:15
【问题描述】:

我正在尝试使绘图可刷,但在某些情况下需要显示“不可用”消息,我使用 validate(need()) 来执行此操作。但是,如果情节已经出现然后变为无效,则刷区仍然存在(见图)。

最小可重现示例:

library(shiny)
ui <- fluidPage(
   checkboxInput("Validate", label="Validate?", value=T),
  plotOutput("MainPlot", brush=brushOpts("MainPlotBrush", direction='x'))
)
server <- function(input, output) {

   output$MainPlot<-renderPlot({
     validate(need(input$Validate, message="This plot failed to render"))
     hist(rnorm(100))
   })
}
shinyApp(ui = ui, server = server)

有没有办法在绘图无效时结束画笔功能?

【问题讨论】:

  • 无论在服务器中生成什么,都使用画笔呈现的 UI。您可以将 plotOutput 移动到服务器以有条件地刷,然后将输出放置为 uiOutput 或 htmlOutput。类似于这里的答案:stackoverflow.com/questions/41120696/…

标签: r shiny


【解决方案1】:

Ryan Morton 的建议提供了一个解决方案,可以在无效时移除画笔。您可以在 renderUI 而不是 renderPlot 中进行验证。

library(shiny)
ui <- fluidPage(
   checkboxInput("Validate", label="Validate?", value=T),
  uiOutput("MainPlotSpot")
)
server <- function(input, output) {

  output$MainPlotSpot<-renderUI({
    validate(need(input$Validate, message="This plot failed to render"))
    plotOutput('MainPlot', brush=brushOpts("MainPlotBrush", direction='x'))
  })
   output$MainPlot<-renderPlot({
     hist(rnorm(100))
   })
}
shinyApp(ui = ui, server = server)

【讨论】:

    猜你喜欢
    • 2013-07-27
    • 2011-09-09
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-14
    • 2015-07-05
    相关资源
    最近更新 更多