【问题标题】:Toggle ggvis-layer with checkbox in a Shiny application在闪亮的应用程序中使用复选框切换 ggvis-layer
【发布时间】:2016-02-18 21:06:31
【问题描述】:

我想添加一个复选框,用于切换 Shiny 应用程序中 ggvis 图中显示的图层。

library(shiny)
library(ggvis)

ui <- shinyUI(fluidPage(sidebarLayout(
   sidebarPanel(
   checkboxInput('loess','loess',TRUE)
  ),
   mainPanel(
   ggvisOutput("plot")
  )
 )))


server <- shinyServer(function(input, output) {

 mtcars %>%
    ggvis(~wt, ~mpg) %>%
    layer_points() %>%
     # if(input$loess) layer_smooths() %>%
    bind_shiny("plot", "plot_ui")
 })

shinyApp(ui = ui, server = server)

这是否可以在 ggvis 管道中使用与上面代码中注释行相同的要点来实现?

【问题讨论】:

    标签: shiny ggvis


    【解决方案1】:

    我不认为你可以直接使用管道。您还需要在reactive 环境中才能访问input$loess。你可以这样做:

    observe({
            plot <- mtcars %>%
                    ggvis(~wt, ~mpg) %>%
                    layer_points()
            if(input$loess) plot <- plot %>% layer_smooths()
            plot %>% bind_shiny("plot", "plot_ui")
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-23
      • 1970-01-01
      • 2016-04-09
      • 1970-01-01
      • 2015-09-25
      • 2015-02-25
      • 2015-06-23
      • 2016-02-22
      相关资源
      最近更新 更多