-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dark mode in new version of dataTables #1085
Comments
Yes, we can try to upgrade DataTables. |
Ok, maybe I'll do the upgrade this week. But how to assign the class |
I don't think you can do it in DT. At least it's not straightforward. You'll have to use JavaScript as instructed at https://datatables.net/manual/styling/dark-mode |
Wait, I did something wrong. I restart. |
I did library(shiny)
library(bslib)
library(DT)
js <- '
$(document).ready(function() {
$("html").attr("data-bs-theme", "dark");
});
'
ui <- page_sidebar(
tags$head(
tags$script(
HTML(js)
)
),
DTOutput("dtable"),
sidebar = sidebar()
)
server <- function(input, output, session) {
output[["dtable"]] <- renderDT({
datatable(iris)
})
}
shinyApp(ui, server) Not dark. Looks like a css is missing? |
I tried
and That' strange because I can see the |
Now I get some errors. This is totally crazy. |
I abdandon. |
Well, this looks complicated indeed, but I think at least you need to tell DT to use the Bootstrap theme (e.g.,
It's |
Note that I got this one with Bootstrap 5-3-2 (downloaded the files on the datatables website). What should I download otherwise ? bslib only supports 5-2 I believe. |
No way with Bootstrap 4. I think it requires Bootstrap 4-6-0 and I see older versions in the |
I abandon again. So to sum up you have to add Bootstrap 5-3-2 as a HTML dependency and it works outside Shiny (up to the ugly pagination). |
WORKS IN SHINY !!!!!!! The "trick" was to put Bootstrap-5.3.2 in the www folder. library(shiny)
library(DT)
ui <- fluidPage(
tags$head(
tags$link(href="bootstrap-5-3-2/css/bootstrap.min.css", rel="stylesheet"),
tags$script(src="bootstrap-5-3-2/js/bootstrap.min.js")
),
DTOutput("dtable"),
)
server <- function(input, output, session) {
output[["dtable"]] <- renderDT({
dtable <- datatable(
iris, style= "bootstrap4",
options = list(initComplete = JS(
'function() {$("html").attr("data-bs-theme", "dark");}')
))
})
}
shinyApp(ui, server) |
What do we do? Even if the dark mode is suspicious, we can upgrade DataTables. We are not obliged to use the dark mode. I do a PR or not? |
You can try to upgrade: https://github.com/rstudio/DT/blob/main/tools/update_DT.R The tricky thing is always testing. Thanks! |
Ok, will do soon. And maybe the dark mode works with bslib, I don't remember whether I tried or not... |
@yihui
The latest version of dataTables has a dark mode. Do you think we can enable it and how if we upgrade?
The text was updated successfully, but these errors were encountered: