我想在笔记本中插入很多桌子,但是要获得位置,请插入一个下拉菜单以选择一个。 我试图复制与绘图相同的方法,但我有下拉菜单,但没有更新...我的数据框在列表中。我认为我们可以尝试在列表中构建所有图形,然后将列表放入带有可见参数的plot_ly函数中,但我不知道是否可行,我正在研究...如果有人对此有所了解。 / p>
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
)
))