Skip to content

Commit de871d8

Browse files
authored
Allow users to filter for tidyverse/official EOL versions or “any version” (#244)
* Allow users to select EOL versions or “any version” * Remove old comments
1 parent 33b20df commit de871d8

File tree

1 file changed

+108
-28
lines changed
  • extensions/runtime-version-scanner

1 file changed

+108
-28
lines changed

extensions/runtime-version-scanner/app.R

Lines changed: 108 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ library(tidyr)
1010
library(shinyjs)
1111
library(future)
1212

13+
# https://devguide.python.org/versions/
14+
PY_OLDEST_SUPPORTED <- "3.9.0"
15+
16+
# https://www.tidyverse.org/blog/2019/04/r-version-support/, https://www.r-project.org/
17+
R_OLDEST_SUPPORTED <- "4.1.0"
18+
19+
# Special version that will be greater than any real version
20+
ANY_VERSION <- "999.99.99"
21+
1322
plan(multisession)
1423

1524
source("get_usage.R")
@@ -66,16 +75,16 @@ ui <- page_sidebar(
6675
bsicons::bs_icon("question-circle-fill"),
6776
tagList(
6877
p(
69-
"Enable a runtime filter and select a version to show ",
70-
"items using versions older than the selected version.",
78+
"Enable a runtime filter and select a version range to ",
79+
"filter content by runtime version.",
7180
),
7281
)
7382
)
7483
),
7584

7685
checkboxInput(
7786
"use_r_cutoff",
78-
label = "R older than…",
87+
label = "R",
7988
value = FALSE
8089
),
8190
conditionalPanel(
@@ -89,7 +98,7 @@ ui <- page_sidebar(
8998

9099
checkboxInput(
91100
"use_py_cutoff",
92-
label = "Python older than…",
101+
label = "Python",
93102
value = FALSE
94103
),
95104
conditionalPanel(
@@ -103,7 +112,7 @@ ui <- page_sidebar(
103112

104113
checkboxInput(
105114
"use_quarto_cutoff",
106-
label = "Quarto older than…",
115+
label = "Quarto",
107116
value = FALSE
108117
),
109118
conditionalPanel(
@@ -115,7 +124,6 @@ ui <- page_sidebar(
115124
)
116125
),
117126

118-
# h5("Filters"),
119127
tags$hr(),
120128

121129
selectizeInput(
@@ -132,22 +140,16 @@ ui <- page_sidebar(
132140

133141
div(
134142
class = "form-group shiny-input-container",
135-
# tags$label(
136-
# "Viewed at least…",
137-
# style = "margin-bottom: 8px; display: inline-block;"
138-
# ),
139143
div(
140-
# this div is getting a height of 52.6
141144
style = "display: flex; align-items: baseline; gap: 6px; height: 36.5px",
142145
numericInput(
143-
# this control has a height of 36.5
144146
"min_views_filter",
145147
label = NULL,
146148
value = 0,
147149
min = 0,
148150
width = "80px",
149151
),
150-
span("times") # this span has a height of 24
152+
span("times")
151153
)
152154
),
153155

@@ -236,15 +238,20 @@ server <- function(input, output, session) {
236238
filter(runtime == "quarto") |>
237239
pull(version)
238240

241+
# Include EOL versions and ANY_VERSION in the additional versions
242+
r_additional_vers <- c(r_server_vers, R_OLDEST_SUPPORTED, ANY_VERSION)
243+
py_additional_vers <- c(py_server_vers, PY_OLDEST_SUPPORTED, ANY_VERSION)
244+
quarto_additional_vers <- c(quarto_server_vers, ANY_VERSION)
245+
239246
content <- get_content(client) |>
240247
filter(app_role %in% c("owner", "editor")) |>
241248
mutate(
242249
owner_username = map_chr(owner, "username"),
243-
r_version = as_ordered_version_factor(r_version, r_server_vers),
244-
py_version = as_ordered_version_factor(py_version, py_server_vers),
250+
r_version = as_ordered_version_factor(r_version, r_additional_vers),
251+
py_version = as_ordered_version_factor(py_version, py_additional_vers),
245252
quarto_version = as_ordered_version_factor(
246253
quarto_version,
247-
quarto_server_vers
254+
quarto_additional_vers
248255
),
249256
)
250257
})
@@ -257,27 +264,62 @@ server <- function(input, output, session) {
257264
pv <- levels(content()$py_version)
258265
qv <- levels(content()$quarto_version)
259266

267+
# Create named vectors for the dropdown choices
268+
r_choices <- rv
269+
py_choices <- pv
270+
quarto_choices <- qv
271+
272+
# Special version labels
273+
r_eol_label <- paste0("tidyverse EOL (< ", R_OLDEST_SUPPORTED, ")")
274+
py_eol_label <- paste0("Official EOL (< ", PY_OLDEST_SUPPORTED, ")")
275+
any_version_label <- "Any version"
276+
277+
# Format labels for all normal versions
278+
format_version_label <- function(version) {
279+
if (version == ANY_VERSION) {
280+
return(any_version_label)
281+
} else {
282+
return(paste0("< ", version))
283+
}
284+
}
285+
286+
# Create names for all choices with formatted labels
287+
names(r_choices) <- sapply(r_choices, format_version_label)
288+
names(py_choices) <- sapply(py_choices, format_version_label)
289+
names(quarto_choices) <- sapply(quarto_choices, format_version_label)
290+
291+
# Find the EOL versions and add special labels
292+
r_eol_index <- which(r_choices == R_OLDEST_SUPPORTED)
293+
py_eol_index <- which(py_choices == PY_OLDEST_SUPPORTED)
294+
295+
if (length(r_eol_index) > 0) {
296+
names(r_choices)[r_eol_index] <- r_eol_label
297+
}
298+
if (length(py_eol_index) > 0) {
299+
names(py_choices)[py_eol_index] <- py_eol_label
300+
}
301+
260302
# Update the R version input
261303
updateSelectizeInput(
262304
session,
263305
"r_version_cutoff",
264-
choices = I(rv),
265-
selected = if (length(rv) > 0) rv[length(rv)] else NULL
306+
choices = r_choices,
307+
selected = if (length(rv) > 0) rv[r_eol_index] else NULL
266308
)
267309

268310
# Update the Python version input
269311
updateSelectizeInput(
270312
session,
271313
"py_version_cutoff",
272-
choices = I(pv),
273-
selected = if (length(pv) > 0) pv[length(pv)] else NULL
314+
choices = py_choices,
315+
selected = if (length(pv) > 0) pv[py_eol_index] else NULL
274316
)
275317

276318
# Update the Quarto version input
277319
updateSelectizeInput(
278320
session,
279321
"quarto_version_cutoff",
280-
choices = I(qv),
322+
choices = quarto_choices,
281323
selected = if (length(qv) > 0) qv[length(qv)] else NULL
282324
)
283325
},
@@ -345,13 +387,20 @@ server <- function(input, output, session) {
345387
return(base)
346388
}
347389

348-
base |>
390+
# Apply filters based on runtime version cutoffs
391+
392+
# Apply the filter
393+
result <- base |>
349394
# fmt: skip
350395
filter(
351396
(input$use_r_cutoff & r_version < input$r_version_cutoff) |
352397
(input$use_py_cutoff & py_version < input$py_version_cutoff) |
353398
(input$use_quarto_cutoff & quarto_version < input$quarto_version_cutoff)
354399
)
400+
401+
# Return the filtered results
402+
403+
result
355404
})
356405

357406
output$selected_versions_html <- renderUI({
@@ -381,18 +430,33 @@ server <- function(input, output, session) {
381430
# Single filter case
382431
if (active_filters == 1) {
383432
if (input$use_r_cutoff) {
433+
label <- if (rv == ANY_VERSION) {
434+
"any R version"
435+
} else {
436+
paste0("R version < ", rv)
437+
}
384438
return(tags$p(HTML(glue::glue(
385-
"Showing {total_count} items using R older than <span class='number-pre'>{rv}</span>."
439+
"Showing {total_count} items using {label}."
386440
))))
387441
}
388442
if (input$use_py_cutoff) {
443+
label <- if (pv == ANY_VERSION) {
444+
"any Python version"
445+
} else {
446+
paste0("Python version < ", pv)
447+
}
389448
return(tags$p(HTML(glue::glue(
390-
"Showing {total_count} items using Python older than <span class='number-pre'>{pv}</span>."
449+
"Showing {total_count} items using {label}."
391450
))))
392451
}
393452
if (input$use_quarto_cutoff) {
453+
label <- if (qv == ANY_VERSION) {
454+
"any Quarto version"
455+
} else {
456+
paste0("Quarto version < ", qv)
457+
}
394458
return(tags$p(HTML(glue::glue(
395-
"Showing {total_count} items using Quarto older than <span class='number-pre'>{qv}</span>."
459+
"Showing {total_count} items using {label}."
396460
))))
397461
}
398462
}
@@ -423,18 +487,33 @@ server <- function(input, output, session) {
423487
# Create list items for multiple filters
424488
li_items <- list()
425489
if (input$use_r_cutoff) {
490+
r_label <- if (rv == ANY_VERSION) {
491+
"Any R version"
492+
} else {
493+
paste0("R version < ", rv)
494+
}
426495
li_items[[length(li_items) + 1]] <- tags$li(HTML(glue::glue(
427-
"R older than <span class='number-pre'>{rv}</span> ({r_count} items)"
496+
"{r_label} ({r_count} items)"
428497
)))
429498
}
430499
if (input$use_py_cutoff) {
500+
py_label <- if (pv == ANY_VERSION) {
501+
"Any Python version"
502+
} else {
503+
paste0("Python version < ", pv)
504+
}
431505
li_items[[length(li_items) + 1]] <- tags$li(HTML(glue::glue(
432-
"Python older than <span class='number-pre'>{pv}</span> ({py_count} items)"
506+
"{py_label} ({py_count} items)"
433507
)))
434508
}
435509
if (input$use_quarto_cutoff) {
510+
quarto_label <- if (qv == ANY_VERSION) {
511+
"Any Quarto version"
512+
} else {
513+
paste0("Quarto version < ", qv)
514+
}
436515
li_items[[length(li_items) + 1]] <- tags$li(HTML(glue::glue(
437-
"Quarto older than <span class='number-pre'>{qv}</span> ({quarto_count} items)"
516+
"{quarto_label} ({quarto_count} items)"
438517
)))
439518
}
440519

@@ -563,6 +642,7 @@ server <- function(input, output, session) {
563642
session$sendCustomMessage("setGuidVisible", input$show_guid)
564643
})
565644

645+
566646
# Download handler
567647
output$export_data <- downloadHandler(
568648
filename = function() {

0 commit comments

Comments
 (0)