我有以下显示数据表的代码。是否可以更改
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)
我们可以添加 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'
)
})