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)
light <- bs_theme(
preset = "bootstrap",
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 = bs_theme(
# preset = "bootstrap",
# base_font = font_google("Inter"),
# theme = light,
# checkboxInput("dark_mode", "Dark mode"),
theme = bs_theme(
version = 5,
preset = "bootstrap",
base_font = font_google("Inter"),
),
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())) {
@ -145,20 +163,20 @@ server <- function(input, output, session) {
output$processed <- renderDT({
out <- cachedData() |>
filter(removed == FALSE) |>
filter(removed == FALSE) |>
group_by(platform, arch) |>
distinct(name) |>
count() |>
arrange(platform) |>
as_tibble()
out <- out |>
mutate("%" = round((n / total_pkgs) * 100, 1))
})
out <- out |>
mutate("%" = round((n / total_pkgs) * 100, 1))
})
output$distinct_success <- renderDT({
out <- cachedData() |>
filter(removed == FALSE) |>
filter(removed == FALSE) |>
group_by(platform, arch) |>
filter(error_occurred == FALSE) |>
distinct(name) |>
@ -166,13 +184,13 @@ server <- function(input, output, session) {
arrange(platform) |>
as_tibble()
out <- out |>
out <- out |>
mutate("%" = round((n / total_pkgs) * 100, 1))
})
output$successful_perc <- renderDT({
out <- cachedData() |>
filter(removed == FALSE) |>
filter(removed == FALSE) |>
group_by(platform, arch) |>
count(error_occurred) |>
mutate("%" = round(n / sum(n) * 100), 2) |>