r - 未选择的条目显示在轴上 - Crosstalk+Plotly 条形图
问题描述
编辑
这似乎是 plotly 社区 github plotly issue #689已经知道的问题,在SO 上有一个类似的问题。
不幸的是,似乎还没有可用的解决方案。任何建议将不胜感激。
我正在尝试使用 Crosstalk 和 Plotly 创建仪表板,但遇到了意想不到的行为。通过 Crosstalk 过滤器进行选择时,Plotly 条形图会为未选择的条目留下“间隙”。
作为一个可重复的例子,假设我想比较城市人口,我得到的是这个(底部的代码):
很可能是我遗漏了一些东西,有没有办法摆脱差距?关于避免该问题的类似比较的可行方法的任何建议?
提前致谢。
代码:
---
title: "Crosstalk+Plotly bargraph selection"
---
```{r setup, include=FALSE}
options(stringsAsFactors = FALSE)
library(crosstalk)
library(dplyr)
library(plotly)
#data on cities' population
city_pop <- data.frame("City" = c("Florence", "Milan", "Venice"),
"Population" = c(382258, 1352000, 261905))
#setting up Crosstalk shared data
sd <- SharedData$new(city_pop, key = city_pop$city)
#filter for the cities
filt <- filter_select(
id = "select_name",
label = "Selected City",
sharedData = sd,
group = ~City,
selected = "")
#barplot of cities' population
bars_pop <- plot_ly(sd, x = ~City, y = ~Population) %>%
add_bars(width=0.2,
x = ~City,
y = ~Population,
color = I("#89CFF0"),
name = "",
opacity=.9,
hoverinfo = 'y',
hovertemplate = paste('%{x} <br> number of Residents: %{y}<extra></extra>')
)
```
```{r, echo=FALSE}
filt
bars_pop
```
解决方案
推荐阅读
- unity3d - 新场景下的 Unity 调用方法
- javascript - jQuery对话框不能第二次调用
- python - 使用 Python Pandas 按不同字符对字符串进行切片
- python - 在 Windows 上安装 simplecrypto 时出错
- javascript - 使用 .call() 的 JavaScript 继承
- c++ - 删除 Netbeans 中的标准运行参数
- jquery - 有没有办法在没有任何第三方插件的情况下让引导自动完成文本字段?
- vbscript - Visual Basic 比较文件任务
- bash - 查看多个 git 仓库的日志
- sql-server - SQL Server: Why is the backup speed so slow?