I can't get ggvis scales to remain fixed with reactive input

余生长醉 提交于 2019-12-06 01:22:40

The answer, thanks to the ggvis google group

  • hardcode the range and domain of the scale, but not reactively.
  • group_by() the categorizing data, to inhibit meaningless animations.

The new server.R code is thus

# server.R
library(shiny)
library(ggvis)
library(dplyr)

shinyServer(function(input, output) {

    selected <- reactive(input$gear)

    selectedData <- reactive({
      mtcars %>%
        filter(gear %in% selected())%>%
        mutate(gear = as.character(gear))%>%
        group_by(gear)
    })

    fill_domain = c("3","4","5")
    fill_range = c("red","blue","green")

    mtcars%>%
      ggvis(~wt, ~mpg)%>%
      layer_points()%>%
      layer_points(data = selectedData, fill = ~gear)%>%
      scale_ordinal("fill", range = fill_range, domain = fill_domain)%>%
      bind_shiny("ggvis", "ggvis_ui")
})
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!