temp save shiny app
This commit is contained in:
parent
9e5c9343a8
commit
418dd6f03b
1 changed files with 144 additions and 0 deletions
144
shiny/app.R
Normal file
144
shiny/app.R
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
library(shiny)
|
||||
library(DBI)
|
||||
library(RPostgres)
|
||||
library(DT)
|
||||
library(bslib)
|
||||
|
||||
# Define UI for the application
|
||||
# ui <- fluidPage(
|
||||
# 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(
|
||||
|
||||
# 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",
|
||||
nav_spacer(),
|
||||
nav_panel("Metadata Query", layout_column_wrap(
|
||||
max_height = "200px",
|
||||
col_widths = c(3, 9),
|
||||
value_box(
|
||||
title = "Total binary count",
|
||||
value = textOutput("totalEntries"),
|
||||
showcase = bsicons::bs_icon("box"),
|
||||
# fill = FALSE,
|
||||
),
|
||||
value_box(
|
||||
title = "SQL Query",
|
||||
# value = textOutput("query"),
|
||||
value = htmlOutput("query"),
|
||||
showcase = bsicons::bs_icon("search"),
|
||||
class = "text-sm"
|
||||
# fill = FALSE,
|
||||
# max_height = 5
|
||||
)
|
||||
), card(
|
||||
full_screen = TRUE,
|
||||
DTOutput("table")
|
||||
)),
|
||||
nav_panel("Statistics"),
|
||||
title = "Binary Package Build Metadata",
|
||||
sidebar = sidebar(
|
||||
conditionalPanel(
|
||||
"input.nav === 'Metadata Query'",
|
||||
width = 12,
|
||||
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()),
|
||||
input_switch("error_occurred", "Error", value = FALSE, width = NULL),
|
||||
# selectInput(, "Error:", c("true", "false", "any"), selected = "false")
|
||||
)
|
||||
),
|
||||
# mainPanel(
|
||||
# )
|
||||
)
|
||||
|
||||
|
||||
# Define server logic
|
||||
server <- function(input, output, session) {
|
||||
# Connect to PostgreSQL database
|
||||
con <- dbConnect(
|
||||
RPostgres::Postgres(),
|
||||
dbname = "build_metadata",
|
||||
host = "r-binaries.devxy.io",
|
||||
port = 15432,
|
||||
user = "r_binaries",
|
||||
password = Sys.getenv("PGPASS")
|
||||
)
|
||||
|
||||
# Query to get the total count of entries
|
||||
output$totalEntries <- renderText({
|
||||
total_query <- "SELECT COUNT(*) AS total_entries FROM single_builds"
|
||||
total_count <- dbGetQuery(con, total_query)
|
||||
pretty_count <- format(as.numeric(total_count$total_entries), big.mark = ".", small.mark = ",", scientific = FALSE)
|
||||
paste(pretty_count)
|
||||
})
|
||||
|
||||
|
||||
# Query and render the filtered data
|
||||
output$table <- renderDT({
|
||||
query <- paste0(
|
||||
"SELECT * FROM single_builds WHERE 1=1 ",
|
||||
if (input$name != "") paste0("AND name = '", input$name, "' "),
|
||||
if (!is.null(input$timestamp)) paste0("AND timestamp BETWEEN '", input$timestamp[1], "' AND '", input$timestamp[2], "' "),
|
||||
if (input$arch != "" && input$arch != "any") paste0("AND arch = '", input$arch, "' "),
|
||||
if (input$platform != "" && input$platform != "any") paste0("AND platform = '", input$platform, "' "),
|
||||
if (input$tag != "") paste0("AND tag = '%", input$tag, "%' "),
|
||||
if (input$error_occurred != "" && input$error_occurred != "any") paste0("AND error_occurred = '", input$error_occurred, "' ")
|
||||
)
|
||||
output$query <- renderUI({
|
||||
tagList(
|
||||
tags$script(src = "prism.js"),
|
||||
shiny::p(query,
|
||||
style = "font-size: 15px;"
|
||||
)
|
||||
)
|
||||
# shiny::p(paste0("<code>", query, "</code"),
|
||||
# style = "font-size: 16px;"
|
||||
# )
|
||||
# paste(query)
|
||||
})
|
||||
|
||||
df <- dbGetQuery(con, query)
|
||||
df <- df[order(df$tag, decreasing = TRUE), ]
|
||||
colnames(df) <- c("Name", "Tag", "Platform", "Error occurred", "Error", "Size (MB)", "Build Timestamp", "Build Duration (s)", "Architecture")
|
||||
datatable(df)
|
||||
})
|
||||
|
||||
# bs_themer()
|
||||
|
||||
# Disconnect on app stop
|
||||
onStop(function() {
|
||||
dbDisconnect(con)
|
||||
})
|
||||
}
|
||||
|
||||
# Run the application
|
||||
shinyApp(ui = ui, server = server)
|
||||
Loading…
Reference in a new issue