feat: add dark mode to shiny app
This commit is contained in:
parent
f7e7df086c
commit
15aec6d907
1 changed files with 41 additions and 23 deletions
64
shiny/app.R
64
shiny/app.R
|
|
@ -7,20 +7,35 @@ library(dplyr)
|
||||||
library(bincraftR)
|
library(bincraftR)
|
||||||
library(data.table)
|
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(
|
ui <- page_navbar(
|
||||||
|
theme = light,
|
||||||
# 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"),
|
|
||||||
),
|
|
||||||
id = "nav",
|
id = "nav",
|
||||||
|
title = "Binary Package Build Metadata",
|
||||||
nav_spacer(),
|
nav_spacer(),
|
||||||
nav_panel("Metadata Query", layout_column_wrap(
|
nav_panel("Metadata Query", layout_column_wrap(
|
||||||
max_height = "200px",
|
max_height = "200px",
|
||||||
|
|
@ -62,7 +77,6 @@ ui <- page_navbar(
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
title = "Binary Package Build Metadata",
|
|
||||||
sidebar = sidebar(
|
sidebar = sidebar(
|
||||||
conditionalPanel(
|
conditionalPanel(
|
||||||
"input.nav === 'Metadata Query'",
|
"input.nav === 'Metadata Query'",
|
||||||
|
|
@ -74,13 +88,17 @@ ui <- page_navbar(
|
||||||
dateRangeInput("timestamp", "Build Date Range:", start = Sys.Date() - 365, end = Sys.Date()),
|
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("error_occurred", "Error during build", value = FALSE, width = NULL),
|
||||||
input_switch("removed", "Removed from CRAN", value = FALSE, width = NULL),
|
input_switch("removed", "Removed from CRAN", value = FALSE, width = NULL),
|
||||||
)
|
),
|
||||||
|
checkboxInput("dark_mode", "Dark mode")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
# Define server logic
|
# Define server logic
|
||||||
server <- function(input, output, session) {
|
server <- function(input, output, session) {
|
||||||
|
observe(session$setCurrentTheme(
|
||||||
|
if (isTRUE(input$dark_mode)) dark else light
|
||||||
|
))
|
||||||
|
|
||||||
# Connect to PostgreSQL database
|
# Connect to PostgreSQL database
|
||||||
con <- dbConnect(
|
con <- dbConnect(
|
||||||
RPostgres::Postgres(),
|
RPostgres::Postgres(),
|
||||||
|
|
@ -132,7 +150,7 @@ server <- function(input, output, session) {
|
||||||
})
|
})
|
||||||
|
|
||||||
cachedData <- reactiveVal(NULL)
|
cachedData <- reactiveVal(NULL)
|
||||||
total_pkgs = length(tools::CRAN_package_db()$Package)
|
total_pkgs <- length(tools::CRAN_package_db()$Package)
|
||||||
|
|
||||||
observeEvent(input, {
|
observeEvent(input, {
|
||||||
if (is.null(cachedData())) {
|
if (is.null(cachedData())) {
|
||||||
|
|
@ -145,20 +163,20 @@ server <- function(input, output, session) {
|
||||||
|
|
||||||
output$processed <- renderDT({
|
output$processed <- renderDT({
|
||||||
out <- cachedData() |>
|
out <- cachedData() |>
|
||||||
filter(removed == FALSE) |>
|
filter(removed == FALSE) |>
|
||||||
group_by(platform, arch) |>
|
group_by(platform, arch) |>
|
||||||
distinct(name) |>
|
distinct(name) |>
|
||||||
count() |>
|
count() |>
|
||||||
arrange(platform) |>
|
arrange(platform) |>
|
||||||
as_tibble()
|
as_tibble()
|
||||||
|
|
||||||
out <- out |>
|
out <- out |>
|
||||||
mutate("%" = round((n / total_pkgs) * 100, 1))
|
mutate("%" = round((n / total_pkgs) * 100, 1))
|
||||||
})
|
})
|
||||||
|
|
||||||
output$distinct_success <- renderDT({
|
output$distinct_success <- renderDT({
|
||||||
out <- cachedData() |>
|
out <- cachedData() |>
|
||||||
filter(removed == FALSE) |>
|
filter(removed == FALSE) |>
|
||||||
group_by(platform, arch) |>
|
group_by(platform, arch) |>
|
||||||
filter(error_occurred == FALSE) |>
|
filter(error_occurred == FALSE) |>
|
||||||
distinct(name) |>
|
distinct(name) |>
|
||||||
|
|
@ -166,13 +184,13 @@ server <- function(input, output, session) {
|
||||||
arrange(platform) |>
|
arrange(platform) |>
|
||||||
as_tibble()
|
as_tibble()
|
||||||
|
|
||||||
out <- out |>
|
out <- out |>
|
||||||
mutate("%" = round((n / total_pkgs) * 100, 1))
|
mutate("%" = round((n / total_pkgs) * 100, 1))
|
||||||
})
|
})
|
||||||
|
|
||||||
output$successful_perc <- renderDT({
|
output$successful_perc <- renderDT({
|
||||||
out <- cachedData() |>
|
out <- cachedData() |>
|
||||||
filter(removed == FALSE) |>
|
filter(removed == FALSE) |>
|
||||||
group_by(platform, arch) |>
|
group_by(platform, arch) |>
|
||||||
count(error_occurred) |>
|
count(error_occurred) |>
|
||||||
mutate("%" = round(n / sum(n) * 100), 2) |>
|
mutate("%" = round(n / sum(n) * 100), 2) |>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue