如何使用 CSS 更改 R 闪亮数据表 csv/excel/columnVisibility 按钮的颜色

问题描述 投票:0回答:1

我有以下显示数据表的代码。是否可以更改

csv
excel
columnVisibility
按钮的颜色?我不确定要更改或修改哪些 CSS 标签才能获得所需的效果。

library(DT)
library(shiny)
library(shinydashboard)


ui <- dashboardPage(
  dashboardHeader(title = "Header"
                  ),
  dashboardSidebar( sidebarMenu(id = "tabs",
                                menuItem("Page1", tabName = "page1"))),
  dashboardBody(
    tabItems(
      tabItem(
        tabName = "page1",
        
        tabBox(id="tabs",
               tabPanel("tab1",
                        column(12,
                               DT::dataTableOutput("table1")
                        ))
        )
      )
    )
  )
)


server <- function(input, output) {
  
  output$table1 <- DT::renderDataTable({
    datatable( data = mtcars,
               options = DToptions,
               extensions = 'Buttons',
               rownames = TRUE,
               selection = 'none'
    )
  })
  

  
  
}

shinyApp(ui, server)
css r button shiny dt
1个回答
3
投票

我们可以添加 javascript/jquery 来更改回调中按钮的颜色:

  output$table1 <- DT::renderDataTable({
    datatable( data = mtcars,
               callback=JS('$("button.buttons-copy").css("background","red"); 
                    $("button.buttons-print").css("background","green"); 
                    return table;'),
               extensions = 'Buttons', options = list(
                 dom = 'Bfrtip',
                 buttons = c('copy', 'print')
               ),
               rownames = TRUE,
               selection = 'none'
    )
  })

© www.soinside.com 2019 - 2024. All rights reserved.