Shiny / ggvis对子集图数据的反应性

在看了GGVIS的演讲之后,我一直在努力创建我的第一个Shiny / ggvis应用程序.我的情节在R中有效,但当我尝试将其迁移到Shiny应用程序以便在网络上显示时,我什么也得不到.单选按钮显示,我可以告诉它似乎工作(我使用rStudio / Shiny / Reactivity教程中的表测试,但它似乎不适合我的ggvis情节).我一直在关注Rstudio上的教程,并使用ggvis源代码中的demo文件夹中的各个部分.我正在尝试创建一个简单的内核密度图,它根据用户输入对数据进行子集并显示分布.附件是我所拥有的可重现的例子.如果我在这里缺少什么,我将不胜感激.

ui.R

# clear memory & load packages
      rm(list=ls())

      library(shiny)
      library(ggvis)

# Define UI for distribution application
    shinyUI(fluidPage(

# Application title
         titlePanel("Diamond Carats by Color/Cut"),

# Sidebar with controls to select subset
          sidebarLayout(
          sidebarPanel(
            radioButtons("cut", "Diamond Cut:",
                         c("Ideal" = "IDEAL",
                           "Premium" = "IDEAL",
                           "Good" = "GOOD",
                           "Very Good" = "VGOOD"))
          ),

#  Display your plot created by GGvis        
            mainPanel(ggvis_output("my_plot"))

          )
        ))

server.R

# clear memory & load packages    
        rm(list=ls())

        library(shiny)
        library(ggvis)

# Define server logic for distribution application

        shinyServer(function(input, output, session) {

# load your data      
          dataset <- diamonds

# Reactive expression to generate the subset.      
          datasetInput <- reactive({                
            selection <-switch(input$cut,
                               IDEAL = "Ideal",
                               PREM = "Premium",
                               GOOD = "Good",
                               VGOOD = "Very Good") 

            subset(dataset, cut == selection)                   
          })


# Generate your plot using GGvis and your reactive inputs      
          gv <- reactive({

            ggvis(datasetInput(), by_group(color),
                  props(x = ~carat,
                        stroke = ~color,
                        fill = ~color,
                        fillOpacity := 0.2,
                        fillOpacity.hover := 0.7)) +
              layer_density()                                
          })


# necessary additions for ggvis integration to shiny        
          output$controls <- renderControls(gv)
          observe_ggvis(gv, "my_plot", session)               
        })

编辑:为了跟进这个问题,我注意到如果我删除以下内容:

            by_group(color)

            stroke = ~color, 
            fill = ~color,

从我在server.R中创建图形的调用开始,图表运行(虽然没有多彩的分组,这是我最初的目的)并且单选按钮成功选择了我的数据子集.如上所述,当我在R中运行图形而不使用反应式子集函数时,图形能够运行并通过菱形颜色改变笔划/填充.目前Shiny to ggvis交互目前不支持此功能吗?或者我只是错误地解释了这个功能?这是我更新的代码,因此您可以看到我的结果:

ui.R

# clear memory & load packages
      rm(list=ls())

      library(shiny)
      library(ggvis)

# Define UI for distribution application
    shinyUI(fluidPage(

# Application title
         titlePanel("Diamond Carats by Color/Cut"),

# Sidebar with controls to select subset
          sidebarLayout(
          sidebarPanel(
            radioButtons("cut", "Diamond Cut:",
                         c("Ideal" = "IDEAL",
                           "Premium" = "IDEAL",
                           "Good" = "GOOD",
                           "Very Good" = "VGOOD"))
          ),

#  Display your plot created by GGvis        
            mainPanel(ggvis_output("my_plot"))

          )
        ))

server.R

# clear memory & load packages    
        rm(list=ls())

        library(shiny)
        library(ggvis)

# Define server logic for distribution application

        shinyServer(function(input, output, session) {

# load your data      
          dataset <- diamonds

# Reactive expression to generate the subset.      
          datasetInput <- reactive({                
            selection <-switch(input$cut,
                               IDEAL = "Ideal",
                               PREM = "Premium",
                               GOOD = "Good",
                               VGOOD = "Very Good") 

            subset(dataset, cut == selection)                   
          })


# Generate your plot using GGvis and your reactive inputs      
          gv <- reactive({

            ggvis(datasetInput(),
                  props(x = ~carat,
                        fillOpacity := 0.2,
                        fillOpacity.hover := 0.7)) +
              layer_density() 

          })


# necessary additions for ggvis integration to shiny        
          output$controls <- renderControls(gv)
          observe_ggvis(gv, "my_plot", session)               
        })

最佳答案 进一步搜索表明这是ggvis:
https://github.com/rstudio/ggvis/issues/71的已知错误

点赞