feat: add dark mode to shiny app

This commit is contained in:
Patrick Schratz 2024-11-18 00:03:40 +01:00
commit 15aec6d907
Signed by: pat-s
GPG key ID: 3C6318841EF78925

View file

@ -7,20 +7,35 @@ library(dplyr)
library(bincraftR)
library(data.table)
ui <- page_navbar(
# theme = bs_theme(
# preset = "bootstrap",
# base_font = font_google("Inter"),
# theme = light,
# checkboxInput("dark_mode", "Dark mode"),
theme = bs_theme(
version = 5,
light <- bs_theme(
preset = "bootstrap",
base_font = font_google("Inter"),
),
base_font = font_google("Inter")
) |>
bslib::bs_add_rules(rules = "
.navbar.navbar-inverse {
background-color: #151b23 !important;
} .navbar-brand {
color: #d1d7e0;}
.navbar-nav .nav-link.active {
color: #d1d7e0; }
")
dark <- bs_theme(
preset = "bootstrap",
bg = "#212830", fg = "white", primary = "#FF9B00",
base_font = font_google("Inter")
) |>
bslib::bs_add_rules(rules = "
.navbar.navbar-inverse {
background-color: #151b23 !important;
} .navbar-brand {
color: #d1d7e0;}
.navbar-nav .nav-link.active {
color: #d1d7e0; }")
ui <- page_navbar(
theme = light,
id = "nav",
title = "Binary Package Build Metadata",
nav_spacer(),
nav_panel("Metadata Query", layout_column_wrap(
max_height = "200px",
@ -62,7 +77,6 @@ ui <- page_navbar(
)
)
),
title = "Binary Package Build Metadata",
sidebar = sidebar(
conditionalPanel(
"input.nav === 'Metadata Query'",
@ -74,13 +88,17 @@ ui <- page_navbar(
dateRangeInput("timestamp", "Build Date Range:", start = Sys.Date() - 365, end = Sys.Date()),
input_switch("error_occurred", "Error during build", value = FALSE, width = NULL),
input_switch("removed", "Removed from CRAN", value = FALSE, width = NULL),
),
checkboxInput("dark_mode", "Dark mode")
)
)
)
# Define server logic
server <- function(input, output, session) {
observe(session$setCurrentTheme(
if (isTRUE(input$dark_mode)) dark else light
))
# Connect to PostgreSQL database
con <- dbConnect(
RPostgres::Postgres(),
@ -132,7 +150,7 @@ server <- function(input, output, session) {
})
cachedData <- reactiveVal(NULL)
total_pkgs = length(tools::CRAN_package_db()$Package)
total_pkgs <- length(tools::CRAN_package_db()$Package)
observeEvent(input, {
if (is.null(cachedData())) {