feat: calculate % in shiny app
This commit is contained in:
parent
8c8a8c0a98
commit
3393fa0a23
1 changed files with 81 additions and 29 deletions
110
shiny/app.R
110
shiny/app.R
|
|
@ -3,26 +3,9 @@ library(DBI)
|
||||||
library(RPostgres)
|
library(RPostgres)
|
||||||
library(DT)
|
library(DT)
|
||||||
library(bslib)
|
library(bslib)
|
||||||
|
library(dplyr)
|
||||||
# Define UI for the application
|
library(bincraftR)
|
||||||
# ui <- fluidPage(
|
library(data.table)
|
||||||
# titlePanel("Binary Package Build Metadata"),
|
|
||||||
# sidebarLayout(
|
|
||||||
# sidebarPanel(
|
|
||||||
# textInput("name", "Package Name:", "ggplot2"),
|
|
||||||
# selectInput("arch", "Architecture:", c("amd64", "arm64", "any"), selected = "amd64"),
|
|
||||||
# selectInput("platform", "Platform:", c("ubuntu-2404", "ubuntu-2204", "redhat-8", "redhat-9", "alpine-320", "any"), selected = "ubuntu-2404"),
|
|
||||||
# textInput("tag", "Tag:", ""),
|
|
||||||
# dateRangeInput("timestamp", "Build Date Range:", start = Sys.Date() - 365, end = Sys.Date()),
|
|
||||||
# selectInput("error_occurred", "Error:", c("true", "false", "any"), selected = "false")
|
|
||||||
# ),
|
|
||||||
# mainPanel(
|
|
||||||
# textOutput("totalEntries"),
|
|
||||||
# textOutput("query"),
|
|
||||||
# DTOutput("table")
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
# )
|
|
||||||
|
|
||||||
ui <- page_navbar(
|
ui <- page_navbar(
|
||||||
|
|
||||||
|
|
@ -61,7 +44,24 @@ ui <- page_navbar(
|
||||||
full_screen = TRUE,
|
full_screen = TRUE,
|
||||||
DTOutput("table")
|
DTOutput("table")
|
||||||
)),
|
)),
|
||||||
nav_panel("Statistics"),
|
nav_panel(
|
||||||
|
"Statistics",
|
||||||
|
layout_column_wrap(
|
||||||
|
# card(card_header(paste0("Distinct package binary count by OS/Arch of", textOutput("total_cran_pkgs"), "possible")),
|
||||||
|
card(card_header("Number of processed packages by OS/Arch"),
|
||||||
|
full_screen = TRUE,
|
||||||
|
DTOutput("processed")
|
||||||
|
),
|
||||||
|
card(card_header("Successful distinct binary builds (n >=1) by OS/Arch"),
|
||||||
|
full_screen = TRUE,
|
||||||
|
DTOutput("distinct_success")
|
||||||
|
),
|
||||||
|
card(card_header("Total successful builds (incl. historic versions)"),
|
||||||
|
full_screen = TRUE,
|
||||||
|
DTOutput("successful_perc")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
title = "Binary Package Build Metadata",
|
title = "Binary Package Build Metadata",
|
||||||
sidebar = sidebar(
|
sidebar = sidebar(
|
||||||
conditionalPanel(
|
conditionalPanel(
|
||||||
|
|
@ -72,12 +72,10 @@ ui <- page_navbar(
|
||||||
selectInput("platform", "Platform:", c("ubuntu-2404", "ubuntu-2204", "redhat-8", "redhat-9", "alpine-320", "any"), selected = "ubuntu-2404"),
|
selectInput("platform", "Platform:", c("ubuntu-2404", "ubuntu-2204", "redhat-8", "redhat-9", "alpine-320", "any"), selected = "ubuntu-2404"),
|
||||||
textInput("tag", "Tag:", ""),
|
textInput("tag", "Tag:", ""),
|
||||||
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", value = FALSE, width = NULL),
|
input_switch("error_occurred", "Error during build", value = FALSE, width = NULL),
|
||||||
# selectInput(, "Error:", c("true", "false", "any"), selected = "false")
|
input_switch("removed", "Removed from CRAN", value = FALSE, width = NULL),
|
||||||
)
|
)
|
||||||
),
|
)
|
||||||
# mainPanel(
|
|
||||||
# )
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -95,7 +93,7 @@ server <- function(input, output, session) {
|
||||||
|
|
||||||
# Query to get the total count of entries
|
# Query to get the total count of entries
|
||||||
output$totalEntries <- renderText({
|
output$totalEntries <- renderText({
|
||||||
total_query <- "SELECT COUNT(*) AS total_entries FROM single_builds"
|
total_query <- "SELECT COUNT(*) AS total_entries FROM single_builds WHERE error_occurred = 'false'"
|
||||||
total_count <- dbGetQuery(con, total_query)
|
total_count <- dbGetQuery(con, total_query)
|
||||||
pretty_count <- format(as.numeric(total_count$total_entries), big.mark = ".", small.mark = ",", scientific = FALSE)
|
pretty_count <- format(as.numeric(total_count$total_entries), big.mark = ".", small.mark = ",", scientific = FALSE)
|
||||||
paste(pretty_count)
|
paste(pretty_count)
|
||||||
|
|
@ -111,7 +109,8 @@ server <- function(input, output, session) {
|
||||||
if (input$arch != "" && input$arch != "any") paste0("AND arch = '", input$arch, "' "),
|
if (input$arch != "" && input$arch != "any") paste0("AND arch = '", input$arch, "' "),
|
||||||
if (input$platform != "" && input$platform != "any") paste0("AND platform = '", input$platform, "' "),
|
if (input$platform != "" && input$platform != "any") paste0("AND platform = '", input$platform, "' "),
|
||||||
if (input$tag != "") paste0("AND tag = '%", input$tag, "%' "),
|
if (input$tag != "") paste0("AND tag = '%", input$tag, "%' "),
|
||||||
if (input$error_occurred != "" && input$error_occurred != "any") paste0("AND error_occurred = '", input$error_occurred, "' ")
|
if (input$error_occurred != "" && input$error_occurred != "any") paste0("AND error_occurred = '", input$error_occurred, "' "),
|
||||||
|
if (input$removed != "" && input$removed != "any") paste0("AND removed = '", input$removed, "' ")
|
||||||
)
|
)
|
||||||
output$query <- renderUI({
|
output$query <- renderUI({
|
||||||
tagList(
|
tagList(
|
||||||
|
|
@ -128,10 +127,63 @@ server <- function(input, output, session) {
|
||||||
|
|
||||||
df <- dbGetQuery(con, query)
|
df <- dbGetQuery(con, query)
|
||||||
df <- df[order(df$tag, decreasing = TRUE), ]
|
df <- df[order(df$tag, decreasing = TRUE), ]
|
||||||
colnames(df) <- c("Name", "Tag", "Platform", "Error occurred", "Error", "Size (MB)", "Build Timestamp", "Build Duration (s)", "Architecture")
|
colnames(df) <- c("Name", "Tag", "Platform", "Error occurred", "Error", "Size (MB)", "Build Timestamp", "Build Duration (s)", "Architecture", "Removed")
|
||||||
datatable(df)
|
datatable(df)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
cachedData <- reactiveVal(NULL)
|
||||||
|
total_pkgs = length(tools::CRAN_package_db()$Package)
|
||||||
|
|
||||||
|
observeEvent(input, {
|
||||||
|
if (is.null(cachedData())) {
|
||||||
|
result <- as.data.table(query_metadata_table())
|
||||||
|
cachedData(result)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
# data = as.data.table(query_metadata_table())
|
||||||
|
|
||||||
|
output$processed <- renderDT({
|
||||||
|
out <- cachedData() |>
|
||||||
|
filter(removed == FALSE) |>
|
||||||
|
group_by(platform, arch) |>
|
||||||
|
distinct(name) |>
|
||||||
|
count() |>
|
||||||
|
arrange(platform) |>
|
||||||
|
as_tibble()
|
||||||
|
|
||||||
|
out <- out |>
|
||||||
|
mutate("%" = round((n / total_pkgs) * 100, 1))
|
||||||
|
})
|
||||||
|
|
||||||
|
output$distinct_success <- renderDT({
|
||||||
|
out <- cachedData() |>
|
||||||
|
filter(removed == FALSE) |>
|
||||||
|
group_by(platform, arch) |>
|
||||||
|
filter(error_occurred == FALSE) |>
|
||||||
|
distinct(name) |>
|
||||||
|
count() |>
|
||||||
|
arrange(platform) |>
|
||||||
|
as_tibble()
|
||||||
|
|
||||||
|
out <- out |>
|
||||||
|
mutate("%" = round((n / total_pkgs) * 100, 1))
|
||||||
|
})
|
||||||
|
|
||||||
|
output$successful_perc <- renderDT({
|
||||||
|
out <- cachedData() |>
|
||||||
|
filter(removed == FALSE) |>
|
||||||
|
group_by(platform, arch) |>
|
||||||
|
count(error_occurred) |>
|
||||||
|
mutate("%" = round(n / sum(n) * 100), 2) |>
|
||||||
|
filter(error_occurred == FALSE) |>
|
||||||
|
select(platform, arch, "%") |>
|
||||||
|
as_tibble()
|
||||||
|
})
|
||||||
|
|
||||||
|
# output$total_cran_pkgs <- renderText(paste("Number of processed packages by OS/Arch of", length(tools::CRAN_package_db()$Package), "(total number of CRAN packages) possible"))
|
||||||
|
# output$total_cran_pkgs = renderText("20000")
|
||||||
|
|
||||||
# bs_themer()
|
# bs_themer()
|
||||||
|
|
||||||
# Disconnect on app stop
|
# Disconnect on app stop
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue