crosstalk的filter_select不会过滤图表

时间:2017-04-14 18:43:55

标签: r ggplot2 plotly flexdashboard

我正在尝试使用crosstalk package,特别是filter_select()函数,制作一个带有过滤到speci的选择框的交互式图表。

例如,我希望以下代码(在例如Flex仪表板中运行)生成一个图表,其中数据集中的国家/地区可以通过交互式输入进行过滤。

library(crosstalk)
library(ggplot2)
library(gapminder)
library(plotly)

sd <- SharedData$new(gapminder)
filter_select("country", "Country:", sd, ~ country)

g <- ggplot(sd, aes(year, lifeExp, color = country, group = country)) +
  geom_line()
ggplotly(g)

虽然我得到了一个“国家:”选择输入,其中包含了国家/地区的名称,但结果图表(下面的屏幕截图)仍包含所有国家/地区,而不仅仅是我输入的国家/地区。

我尝试将图形显示为普通ggplot而不是调用ggplotly,并尝试在flexdashboard和R笔记本中运行它,但输入最终不会影响图形。如何使情节互动?

enter image description here

以下会话信息。顺便说一句,你需要使用sqly的dev版本(从GitHub安装)来使用带有串扰的情节。

Session info ----------------------------------------------------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.3 (2017-03-06)
 system   x86_64, darwin13.4.0        
 ui       RStudio (1.0.136)           
 language (EN)                        
 collate  en_US.UTF-8                 
 tz       America/New_York            
 date     2017-04-14                  

Packages --------------------------------------------------------------------------------------------------------------------------------------------------
 package       * version    date       source                            
 assertthat      0.2.0      2017-04-11 cran (@0.2.0)                     
 backports       1.0.4      2016-10-24 cran (@1.0.4)                     
 base64enc       0.1-3      2015-07-28 CRAN (R 3.3.0)                    
 colorspace      1.2-6      2015-03-11 CRAN (R 3.3.0)                    
 crosstalk     * 1.0.1      2017-04-07 Github (rstudio/crosstalk@d8f29eb)
 devtools        1.12.0     2016-06-24 CRAN (R 3.3.0)                    
 digest          0.6.12     2017-01-27 cran (@0.6.12)                    
 dplyr           0.5.0.9001 2017-04-11 Github (hadley/dplyr@1b0ae13)     
 evaluate        0.10       2016-10-11 cran (@0.10)                      
 flexdashboard   0.2.0      2016-05-18 CRAN (R 3.3.0)                    
 gapminder     * 0.2.0      2015-12-31 CRAN (R 3.3.0)                    
 ggplot2       * 2.2.1.9000 2017-04-14 Github (hadley/ggplot2@f4398b6)   
 glue            0.0.0.9000 2017-03-30 Github (tidyverse/glue@6e77c3b)   
 gtable          0.2.0      2016-02-26 CRAN (R 3.3.0)                    
 htmltools     * 0.3.5      2016-03-21 CRAN (R 3.3.0)                    
 htmlwidgets     0.8        2016-11-09 cran (@0.8)                       
 httpuv          1.3.3      2015-08-04 CRAN (R 3.3.0)                    
 httr            1.2.1      2016-07-03 cran (@1.2.1)                     
 jsonlite        1.4        2017-04-08 cran (@1.4)                       
 knitr           1.15.19    2017-04-14 Github (yihui/knitr@0c2abf8)      
 labeling        0.3        2014-08-23 CRAN (R 3.3.0)                    
 lazyeval        0.2.0      2016-06-12 cran (@0.2.0)                     
 magrittr        1.5        2014-11-22 CRAN (R 3.3.0)                    
 memoise         1.0.0      2016-01-29 CRAN (R 3.3.0)                    
 mime            0.5        2016-07-07 cran (@0.5)                       
 munsell         0.4.3      2016-02-13 CRAN (R 3.3.0)                    
 plotly        * 4.5.6.9000 2017-04-14 Github (ropensci/plotly@4ffae1c)  
 plyr            1.8.4      2016-06-08 cran (@1.8.4)                     
 purrr           0.2.2      2016-06-18 cran (@0.2.2)                     
 R6              2.2.0      2016-10-05 cran (@2.2.0)                     
 Rcpp            0.12.10    2017-04-13 Github (RcppCore/Rcpp@21d8388)    
 rlang           0.0.0.9006 2017-04-11 Github (hadley/rlang@0756eaf)     
 rmarkdown       1.3        2016-12-21 CRAN (R 3.3.0)                    
 rprojroot       1.1        2016-10-29 cran (@1.1)                       
 rsconnect       0.7        2016-12-21 CRAN (R 3.3.0)                    
 rstudioapi      0.6        2016-06-27 cran (@0.6)                       
 scales          0.4.1.9000 2016-11-28 Github (hadley/scales@89c2a2f)    
 shiny           1.0.1      2017-04-01 cran (@1.0.1)                     
 stringi         1.1.5      2017-04-07 cran (@1.1.5)                     
 stringr         1.2.0      2017-02-18 cran (@1.2.0)                     
 tibble          1.3.0      2017-04-01 cran (@1.3.0)                     
 tidyr           0.6.1      2017-01-10 CRAN (R 3.3.2)                    
 viridisLite     0.2.0      2017-03-24 cran (@0.2.0)                     
 withr           1.0.2      2016-06-20 cran (@1.0.2)                     
 xtable          1.8-2      2016-02-05 CRAN (R 3.3.0)                    
 yaml            2.1.14     2016-11-12 cran (@2.1.14)                    

1 个答案:

答案 0 :(得分:4)

这是由于剧情中的错误现在已经修复,谢谢!

https://github.com/ropensci/plotly/issues/950