egenn commited on
Commit
3498741
·
1 Parent(s): d44362b

add support for GitHub data

Browse files
Files changed (2) hide show
  1. app.R +68 -13
  2. globals.R +45 -39
app.R CHANGED
@@ -4,7 +4,7 @@
4
 
5
  # shiny::runApp("./")
6
  # Setup
7
- rtemisseq_version <- "0.2.8"
8
  library(rtemis)
9
  library(rtemisbio)
10
  library(shiny)
@@ -32,7 +32,7 @@ success <- "#60D0DA"
32
  #' @return A shiny app that can be converted to a shinylive app
33
 
34
  rtemisseq <- function(
35
- default_theme = "light",
36
  protein_plotly_height = "900px",
37
  jsonedit_height = "900px",
38
  verbosity = 0) {
@@ -87,22 +87,17 @@ rtemisseq <- function(
87
  ),
88
  # Theme ----
89
  theme = bslib::bs_theme(
90
- # bg = "#fff",
91
- # fg = "#000",
92
  `tooltip-opacity` = 1,
93
  `tooltip-border-radius` = "10px",
94
  `tooltip-padding-x` = "1rem",
95
  `tooltip-padding-y` = "1rem",
96
  `tooltip-font-size` = "1rem"
97
- # base_font = bslib::font_google("Inter"), # doesn't work in shinylive
98
- # code_font = bslib::font_google("Fira Code")
99
  ) |>
100
  bs_add_rules(sass::sass_file("www/rtemislive.scss")),
101
  # Window title ----
102
  window_title = "rtemisSeq",
103
  # Language ----
104
  lang = "en",
105
- # tags$script(src = "globals.js"),
106
  # Nav Panels ----
107
  ## [] Welcome ----
108
  bslib::nav_panel(
@@ -117,7 +112,8 @@ rtemisseq <- function(
117
  "rtemisSeq is a web interface for ",
118
  as.character(a("rtemisbio", href = "https://rtemis.org/rtemisbio", target = "_blank")),
119
  ", <br>providing interactive visualization of sequence data.",
120
- "<br>Created for the ", as.character(a("FTD CWOW", href = "https://cwow.ucsf.edu/", target = "_blank")),
 
121
  ".<br><br>",
122
  rthelp_inline(
123
  "To get started, use the navigation tabs at the top.",
@@ -232,7 +228,6 @@ rtemisseq <- function(
232
  img(
233
  src = "rtemis_gray.png",
234
  alt = "rtemis",
235
- # align = "center",
236
  width = "190px"
237
  ),
238
  href = "https://rtemis.org",
@@ -248,8 +243,7 @@ rtemisseq <- function(
248
  # busy indicators ----
249
  shinybusy::add_busy_spinner(
250
  spin = "orbit",
251
- # color = "#72CDF4",
252
- color = "#00ffff",
253
  timeout = 200,
254
  position = "bottom-left",
255
  onstart = FALSE
@@ -271,13 +265,50 @@ rtemisseq <- function(
271
  label = "Data source",
272
  choices = list(
273
  `Built-in datasets` = "builtin",
274
- # `GitHub repository` = "github",
275
  `File upload` = "upload"
276
  ),
277
  selected = "builtin"
278
  )
279
  })
280
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
281
  # UI a3 Data ----
282
  output$ui_a3_data_load <- shiny::renderUI({
283
  req(input$a3_load_switch)
@@ -292,7 +323,15 @@ rtemisseq <- function(
292
  buttonLabel = "Browse local files...",
293
  )
294
  } else if (input$a3_load_switch == "github") {
295
-
 
 
 
 
 
 
 
 
296
  } else {
297
  # Select built-in data stored in ./data/ directory
298
  if (verbosity > 0) {
@@ -352,6 +391,22 @@ rtemisseq <- function(
352
  message("Loaded dataset of class '", class(dat)[1], "'")
353
  }
354
  return(dat)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
355
  } else {
356
  # Load built-in data from data.R objects
357
  req(input$a3_builtin_data)
 
4
 
5
  # shiny::runApp("./")
6
  # Setup
7
+ rtemisseq_version <- "0.3.0"
8
  library(rtemis)
9
  library(rtemisbio)
10
  library(shiny)
 
32
  #' @return A shiny app that can be converted to a shinylive app
33
 
34
  rtemisseq <- function(
35
+ default_theme = "dark",
36
  protein_plotly_height = "900px",
37
  jsonedit_height = "900px",
38
  verbosity = 0) {
 
87
  ),
88
  # Theme ----
89
  theme = bslib::bs_theme(
 
 
90
  `tooltip-opacity` = 1,
91
  `tooltip-border-radius` = "10px",
92
  `tooltip-padding-x` = "1rem",
93
  `tooltip-padding-y` = "1rem",
94
  `tooltip-font-size` = "1rem"
 
 
95
  ) |>
96
  bs_add_rules(sass::sass_file("www/rtemislive.scss")),
97
  # Window title ----
98
  window_title = "rtemisSeq",
99
  # Language ----
100
  lang = "en",
 
101
  # Nav Panels ----
102
  ## [] Welcome ----
103
  bslib::nav_panel(
 
112
  "rtemisSeq is a web interface for ",
113
  as.character(a("rtemisbio", href = "https://rtemis.org/rtemisbio", target = "_blank")),
114
  ", <br>providing interactive visualization of sequence data.",
115
+ "<br>Created for the ",
116
+ as.character(a("FTD CWOW", href = "https://cwow.ucsf.edu/", target = "_blank")),
117
  ".<br><br>",
118
  rthelp_inline(
119
  "To get started, use the navigation tabs at the top.",
 
228
  img(
229
  src = "rtemis_gray.png",
230
  alt = "rtemis",
 
231
  width = "190px"
232
  ),
233
  href = "https://rtemis.org",
 
243
  # busy indicators ----
244
  shinybusy::add_busy_spinner(
245
  spin = "orbit",
246
+ color = "#FF8F28",
 
247
  timeout = 200,
248
  position = "bottom-left",
249
  onstart = FALSE
 
265
  label = "Data source",
266
  choices = list(
267
  `Built-in datasets` = "builtin",
268
+ `GitHub repository` = "github",
269
  `File upload` = "upload"
270
  ),
271
  selected = "builtin"
272
  )
273
  })
274
 
275
+ # GitHub file list ----
276
+ # GitHub file list udpate button ----
277
+ output$ui_github_files_update_button <- shiny::renderUI({
278
+ if (verbosity > 0) {
279
+ message("Rendering ui_github_files_update_button")
280
+ }
281
+ bslib::input_task_button(
282
+ "github_files_update_button",
283
+ "Update GitHub file list",
284
+ icon = bsicons::bs_icon("arrow-clockwise"),
285
+ label_busy = "Updating...",
286
+ icon_busy = bsicons::bs_icon("clock-history"),
287
+ type = "primary",
288
+ auto_reset = TRUE
289
+ )
290
+ }) # /ui_github_files_update_button
291
+
292
+ # GitHub files runs when github_files_update_button is clicked ----
293
+ github_files <- reactive({
294
+ get_github_files(repo_owner = "rtemis-org", repo_name = "seq-data", verbosity = verbosity)
295
+ }) |>
296
+ bindEvent(input$github_files_update_button)
297
+
298
+ # GitHub file list output ----
299
+ output$ui_github_files <- shiny::renderUI({
300
+ req(github_files())
301
+ if (verbosity > 0) {
302
+ message("Rendering ui_github_files")
303
+ }
304
+ shiny::selectizeInput(
305
+ inputId = "github_file",
306
+ label = "Select a file from the GitHub repository",
307
+ choices = github_files()$file_name,
308
+ selected = github_files()$file_name[1]
309
+ )
310
+ }) # /ui_github_files
311
+
312
  # UI a3 Data ----
313
  output$ui_a3_data_load <- shiny::renderUI({
314
  req(input$a3_load_switch)
 
323
  buttonLabel = "Browse local files...",
324
  )
325
  } else if (input$a3_load_switch == "github") {
326
+ # "Update GitHub file list" button
327
+ if (verbosity > 0) {
328
+ message("Rendering ui_a3_data_load for GitHub file list")
329
+ }
330
+ # UI output with GitHub file list & update button
331
+ shiny::tagList(
332
+ uiOutput("ui_github_files"),
333
+ uiOutput("ui_github_files_update_button")
334
+ )
335
  } else {
336
  # Select built-in data stored in ./data/ directory
337
  if (verbosity > 0) {
 
391
  message("Loaded dataset of class '", class(dat)[1], "'")
392
  }
393
  return(dat)
394
+ } else if (input$a3_load_switch == "github") {
395
+ # Download GitHub file
396
+ req(input$github_file)
397
+ if (verbosity > 0) {
398
+ message("Downloading GitHub file '", input$github_file, "'")
399
+ }
400
+ # index with input$github_file
401
+ jsondat <- httr::GET(
402
+ github_files()[github_files()$file_name == input$github_file, "download_url"]
403
+ ) |> httr::content(as = "text", encoding = "UTF-8")
404
+ dat <- as.a3(jsonlite::parse_json(
405
+ jsondat,
406
+ simplifyVector = TRUE,
407
+ simplifyMatrix = FALSE
408
+ ))
409
+ return(dat)
410
  } else {
411
  # Load built-in data from data.R objects
412
  req(input$a3_builtin_data)
globals.R CHANGED
@@ -2,46 +2,11 @@
2
  # ::rtemisseq::
3
  # EDG rtemis.org
4
 
5
- # Themes ----
6
- # {bg_dark, bg_light} also used by plot.bg
7
- bg_dark <- "#191919"
8
- bg_light <- "#ffffff"
9
- primary_dark <- "#72CDF4"
10
- primary_light <- "#1295D8"
11
- seconday_dark <- "#808080"
12
- secondary_light <- "#808080"
13
- info_dark <- "#FEB2E0"
14
- info_light <- "#E44C9A"
15
- success_dark <- "#B4DC55"
16
- success_light <- "#84C234"
17
 
18
- bslib_dark <- bslib::bs_theme(
19
- bg = bg_dark,
20
- fg = "#fff",
21
- primary = primary_dark,
22
- secondary = seconday_dark,
23
- success = success_dark,
24
- info = info_dark,
25
- `tooltip-bg` = "#bbbbbb",
26
- `tooltip-color` = info_dark,
27
- `tooltip-opacity` = .95
28
- ) |>
29
- bslib::bs_add_rules(sass::sass_file("www/rtemislive.scss"))
30
-
31
- bslib_light <- bslib::bs_theme(
32
- bg = bg_light,
33
- fg = "#000",
34
- primary = primary_light,
35
- secondary = secondary_light,
36
- success = success_light,
37
- info = info_light,
38
- `tooltip-bg` = "#303030",
39
- `tooltip-color` = info_light,
40
- `tooltip-opacity` = .95
41
- ) |>
42
- bslib::bs_add_rules(sass::sass_file("www/rtemislive.scss"))
43
-
44
- # from rtemislive
45
  rthelp <- function(..., title = NULL, class = "rthelp") {
46
  div(
47
  div(HTML(paste0(title, " Instructions")),
@@ -110,3 +75,44 @@ summarize_a3 <- function(x) {
110
  )
111
  )
112
  } # rtemisseq::summarize_a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  # ::rtemisseq::
3
  # EDG rtemis.org
4
 
5
+ # rtemis ----
6
+ msg2start <- getFromNamespace("msg2start", "rtemis")
7
+ msg2done <- getFromNamespace("msg2done", "rtemis")
 
 
 
 
 
 
 
 
 
8
 
9
+ # rtemislive ----
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  rthelp <- function(..., title = NULL, class = "rthelp") {
11
  div(
12
  div(HTML(paste0(title, " Instructions")),
 
75
  )
76
  )
77
  } # rtemisseq::summarize_a3
78
+
79
+ #' Get file names and download URLs from a GitHub repository
80
+ #'
81
+ #' @param repo_owner The owner of the GitHub repository
82
+ #' @param repo_name The name of the GitHub repository
83
+ #' @return A data frame with file names and download URLs
84
+ #' @examples
85
+ #' files <- get_github_files("rtemis-org", "seq-data")
86
+ #' @export
87
+ #' @import httr
88
+ #' @import jsonlite
89
+
90
+ get_github_files <- function(repo_owner, repo_name, verbosity = 1) {
91
+ if (verbosity > 0) {
92
+ msg2start("Getting file information from", paste0(repo_owner, "/", repo_name))
93
+ }
94
+ # Construct the API URL
95
+ api_url <- paste0("https://api.github.com/repos/", repo_owner, "/", repo_name, "/contents/data")
96
+
97
+ # Make the API request
98
+ response <- GET(api_url)
99
+
100
+ # Check if the request was successful
101
+ if (response[["status_code"]] == 200) {
102
+ # Extract the file information
103
+ files_data <- content(response, as = "text", encoding = "UTF-8") |> fromJSON()
104
+
105
+ # Create a data frame with file names and download URLs
106
+ files_df <- data.frame(
107
+ file_name = files_data[["name"]],
108
+ download_url = files_data[["download_url"]]
109
+ )
110
+ if (verbosity > 0) {
111
+ msg2done()
112
+ }
113
+ return(files_df)
114
+ } else {
115
+ print("Error: Could not retrieve file information.")
116
+ return(NULL)
117
+ }
118
+ } # rtemis::get_github_files