Skip to content
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

Suggestion: make {reactable} interact correctly with {bs4Dash}'s dark-mode #290

Open
eastclintw00d opened this issue Nov 17, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@eastclintw00d
Copy link

Please have a look at the following examples:

Example 1: In dark-mode font color changes to white and becomes unreadable because of the white background.

library(shiny)
library(bs4Dash)
library(reactable)

shinyApp(
  ui = dashboardPage(
    header = dashboardHeader(),
    sidebar = dashboardSidebar(),
    body = dashboardBody(
      box(width = 4, reactableOutput("table"))
    ),
    title = "DashboardPage"
  ),
  server = function(input, output) { 
    output$table <- renderReactable({
      data.frame(
        col1 = paste0("col1_", 1:10),
        col2 = paste0("col2_", 1:10),
        col3 = paste0("col3_", 1:10),
        col4 = paste0("col4_", 1:10),
        col5 = paste0("col5_", 1:10),
        col6 = paste0("col6_", 1:10),
        col7 = paste0("col7_", 1:10),
        col8 = paste0("col8_", 1:10),
        col9 = paste0("col9_", 1:10)
      ) |> 
        reactable(
          columns = list(
            col1 = colDef(sticky = "left"),
            col9 = colDef(sticky = "right")
          )
        )
    })
  }
)

Example 2: Setting background to "transparent" solves the dark-mode readability issue but create issues with sticky columns.

library(shiny)
library(bs4Dash)
library(reactable)

shinyApp(
  ui = dashboardPage(
    header = dashboardHeader(),
    sidebar = dashboardSidebar(),
    body = dashboardBody(
      box(width = 4, reactableOutput("table"))
    ),
    title = "DashboardPage"
  ),
  server = function(input, output) { 
    output$table <- renderReactable({
      data.frame(
        col1 = paste0("col1_", 1:10),
        col2 = paste0("col2_", 1:10),
        col3 = paste0("col3_", 1:10),
        col4 = paste0("col4_", 1:10),
        col5 = paste0("col5_", 1:10),
        col6 = paste0("col6_", 1:10),
        col7 = paste0("col7_", 1:10),
        col8 = paste0("col8_", 1:10),
        col9 = paste0("col9_", 1:10)
      ) |> 
        reactable(
          theme = reactableTheme(backgroundColor = "transparent"),
          columns = list(
            col1 = colDef(sticky = "left"),
            col9 = colDef(sticky = "right")
          )
        )
    })
  }
)

As imho the package bs4Dash is becoming popular it would be a nice feature to have a built-in dark-mode functionality.

@glin
Copy link
Owner

glin commented Dec 10, 2022

Thanks for the suggestion and those examples. I have to admit, I don't know enough about bs4Dash to provide a good answer on how to do this (and don't have time to research right now), but agree that it would be great to make dynamic dark mode toggles easy to integrate with reactable. Maybe it's time to revisit bslib integration (#96), if bs4Dash does use bslib.

From a quick look at that example app, I do see that bs4Dash sets a top-level .dark-mode class when dark mode is toggled. If that's a publicly documented class, then you could use reactableTheme()'s nested selectors feature to conditionally style the table's text color and background color when dark mode is activated. There's an example of this at Theming - Nested selectors, and here's the example app modified to do the same:

library(shiny)
library(bs4Dash)
library(reactable)

shinyApp(
  ui = dashboardPage(
    header = dashboardHeader(),
    sidebar = dashboardSidebar(),
    body = dashboardBody(
      box(width = 4, reactableOutput("table"))
    ),
    title = "DashboardPage"
  ),
  server = function(input, output) {
    output$table <- renderReactable({
      data.frame(
        col1 = paste0("col1_", 1:10),
        col2 = paste0("col2_", 1:10),
        col3 = paste0("col3_", 1:10),
        col4 = paste0("col4_", 1:10),
        col5 = paste0("col5_", 1:10),
        col6 = paste0("col6_", 1:10),
        col7 = paste0("col7_", 1:10),
        col8 = paste0("col8_", 1:10),
        col9 = paste0("col9_", 1:10)
      ) |>
        reactable(
          theme = reactableTheme(
            # Dark mode theme for bs4Dash
            style = list(
              ".dark-mode &" = list(
                color = "#fff",
                backgroundColor = "#343a40"
              )
            )
          ),
          columns = list(
            col1 = colDef(sticky = "left"),
            col9 = colDef(sticky = "right")
          )
        )
    })
  }
)

@glin glin added the enhancement New feature or request label Dec 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants