我试图切换显示/隐藏列按钮的标签,并保持跟踪它被点击的次数,以便改变显示的表的列数。我做到了,但我不能使用计数器值的直接偶数/奇数微分。相反,我必须使用它:LOCALE_ID
使其工作,因为每次单击都会更改计数器2次。我想要一个更简单的程序,也许有一个闪亮的BS?
(vars$counter+1)/2) %% 2 == 0)
答案 0 :(得分:1)
因为我不是100%你想要的,这是它吗?请注意,我使用了其他库,例如shinyBS
rm(list = ls())
library(shiny)
library(shinydashboard)
library(DT)
library(shinyBS)
body <- dashboardBody(bsButton("showallcolumns", label = "Hide", block = F, style="danger",icon=icon("hand-pointer-o")),br(),DT::dataTableOutput('table2'))
ui <- dashboardPage(dashboardHeader(),dashboardSidebar(),body)
server <- function(input, output,session) {
table <- data.frame(replicate(10,sample(0:1,1000,rep=TRUE)))
vars <- reactiveValues(counter = 1:10)
observeEvent(input$showallcolumns,{
if(input$showallcolumns %% 2){
updateButton(session, "showallcolumns",label = "Show", block = F, style = "success",icon=icon("hand-pointer-o"))
vars$counter <- 1:5
}
else{
updateButton(session, "showallcolumns",label = "Hide", block = F, style = "danger",icon=icon("hand-pointer-o"))
vars$counter <- 1:10
}
})
output$table2 = DT::renderDataTable({
DT::datatable(table[, vars$counter])
})
} # end server
shinyApp(ui, server)