首页 > 解决方案 > 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
                           )
                      ))

标签: rr-markdownplotlyrnotebook

解决方案


推荐阅读