r - R下拉菜单,带有表格
问题描述
我想在我的笔记本中插入很多表格,但要获得位置,请插入一个下拉菜单来选择一个。我试图复制与绘图相同的方法,我有我的下拉菜单,但它没有更新......我的数据框在一个列表中。我认为我们可以尝试在列表中构建所有图形,并将列表放入带有可见参数的 plot_ly 函数中,但我不知道这是否可能,我正在努力……如果有人对此有所了解……
A<-data.frame(FE=c(1,2,3,4),FB=c(4,5,6,9))
B<-data.frame(FA=c(5,6,7,8),FB=c(8,2,1,0))
mydf<-list(A,B)
cellValues <- list()
for (i in (0:ncol(mydf[[1]]))) {
row <- mydf[[1]][i]
cellValues[i] <- row
}
p <- plot_ly(
type = 'table',
header = list(
values = colnames(mydf[[1]]),
align = c('center', rep('center', ncol(mydf[[1]]))),
line = list(width = 1, color = 'black'),
fill = list(color = 'rgb(0, 29, 67)'),
font = list(family = "Arial", size = 14, color = "white")
),
cells = list(
values = cellValues,
align = c('center', rep('center', ncol(mydf[[1]]))),
line = list(color = "black", width = 1),
fill = list(color = c('rgb(0, 29, 67)', 'rgba(228, 222, 249, 0.65)')),
font = list(family = "Arial", size = 12, color = c("white","black"))
))
g<-p
g<-add_table(type="table",header = list(
values = colnames(mydf[[2]]),
align = c('center', rep('center', ncol(mydf[[2]]))),
line = list(width = 1, color = 'black'),
fill = list(color = 'rgb(0, 29, 67)'),
font = list(family = "Arial", size = 14, color = "white")
),
cells = list(
values = cellValues,
align = c('center', rep('center', ncol(mydf[[2]]))),
line = list(color = "black", width = 1),
fill = list(color = c('rgb(0, 29, 67)', 'rgba(228, 222, 249, 0.65)')),
font = list(family = "Arial", size = 12, color = c("white","black"))
),visible=FALSE)
recap_option<-list()
list_visible<-list()
list_visible[[1]]<-list(TRUE,FALSE)
list_visible[[2]]<-list(FALSE,TRUE)
recap_option[[1]]<-list(method="restyle",
args=list(list(visible=c(TRUE,FALSE))),
label="A")
recap_option[[2]]<-list(method="restyle",
args=list(list(visible=c(FALSE,TRUE))),
label="B")
g%>%layout(title = 'Evolution composition du PIB',
updatemenus=list(
list(
buttons=recap_option
)
))
解决方案
推荐阅读
- cookies - _abck 和 bm_sz 的用途是什么?
- flutter - 异步函数不等待
- google-analytics - 行为部分中的 Google 分析事件未显示
- css - 渐变动画使 CSS 无法在 Internet Explorer/Edge/Safari 上正确显示
- z3 - 变量是否有最大值大小?
- java - 在 RecyclerView 中显示多个数据时出现 java.lang.IndexOutOfBoundsException
- java - 检索 Apache circularfifobuffer 中最后一项的计算效率最高的方法是什么?
- r - ggplot2 堆积条形图,每个 X 变量 2 个条形图
- scala - Spark 会话目录失败
- heroku - Heroku 网站可以读取 Server Side Includes