@@ -4,80 +4,54 @@ run_addin <- function() {
44 # library(shiny)
55 # library(miniUI)
66
7- selectTutorial <- function () {
8- tutorials <- dir(system.file(" tutorials" , package = " BioDataScience2" ))
9- if (! length(tutorials )) return (NULL )
7+ selectItem <- function () {
8+ package <- " BioDataScience2"
9+
10+ items <- character (0 )
11+ tutorials <- dir(system.file(" tutorials" , package = package ))
12+ if (length(tutorials ))
13+ items <- paste(tutorials , " (tutorial)" )
14+ apps <- dir(system.file(" shiny" , package = package ))
15+ if (length(apps ))
16+ items <- c(items , paste(apps , " (Shiny app)" ))
17+ if (! length(items )) return ()
1018
1119 ui <- miniPage(
1220 miniContentPanel(
13- selectInput(" tutorial " , " Tutorials in BioDataScience2: " ,
14- selectize = FALSE , size = 11 , tutorials )
21+ selectInput(" item " , paste0( " Items in " , package , " : " ) ,
22+ selectize = FALSE , size = 11 , items )
1523 ),
16- gadgetTitleBar(" " , left = miniTitleBarCancelButton(), right =
17- miniTitleBarButton(" done" , " Select" , primary = TRUE ))
24+ gadgetTitleBar(" " ,
25+ left = miniTitleBarCancelButton(),
26+ right = miniTitleBarButton(" done" , " Select" , primary = TRUE )
27+ )
1828 )
1929
2030 server <- function (input , output , session ) {
2131 observeEvent(input $ done , {
22- returnValue <- input $ tutorial
23- if (! is.null(returnValue ))
24- BioDataScience2 :: run(returnValue )
32+ returnValue <- input $ item
33+ if (! is.null(returnValue )) {
34+ if (grepl(" \\ (tutorial\\ )$" , returnValue )) {
35+ run(sub(" \\ (tutorial\\ )$" , " " , returnValue ))
36+ } else {# Must be an app then
37+ run_app(sub(" \\ (Shiny app\\ )$" , " " , returnValue ))
38+ }
39+ }
2540 stopApp(returnValue )
2641 })
2742 }
2843
2944 runGadget(ui , server ,
30- viewer = dialogViewer(" Select a tutorial " ,
45+ viewer = dialogViewer(" Select an item " ,
3146 width = 300 , height = 250 ))
3247 }
3348
34- tutorial <- try(suppressMessages(selectTutorial()), silent = TRUE )
35- if (! is.null(tutorial ) && ! inherits(tutorial , " try-error" ))
36- message(" Running tutorial " , tutorial )
37- }
38-
39- run_app_addin <- function () {
40- # library(shiny)
41- # library(miniUI)
42-
43- selectApp <- function () {
44- apps <- dir(system.file(" shiny" , package = " BioDataScience2" ))
45- if (! length(apps )) return (NULL )
46-
47- ui <- miniPage(
48- miniContentPanel(
49- selectInput(" app" , " Shiny apps in BioDataScience2:" ,
50- selectize = FALSE , size = 11 , apps )
51- ),
52- gadgetTitleBar(" " , left = miniTitleBarCancelButton(), right =
53- miniTitleBarButton(" done" , " Select" , primary = TRUE ))
54- )
55-
56- server <- function (input , output , session ) {
57- observeEvent(input $ done , {
58- returnValue <- input $ app
59- if (! is.null(returnValue ))
60- BioDataScience2 :: run_app(returnValue )
61- stopApp(returnValue )
62- })
63- }
64-
65- runGadget(ui , server ,
66- viewer = dialogViewer(" Select a Shiny application" ,
67- width = 300 , height = 250 ))
68- }
69-
70- app <- try(suppressMessages(selectApp()), silent = TRUE )
71- if (! is.null(app ) && ! inherits(app , " try-error" ))
72- message(" Running Shiny application " , app )
73- }
74-
75- update_pkg_addin <- function () {
7649 # Update both BioDataScience & BioDataScience2
7750 learndown :: update_pkg(" BioDataScience" ,
7851 github_repos = " BioDataScience-course/BioDataScience" )
7952 update_pkg()
80- }
8153
82- sign_out_addin <- function ()
83- BioDataScience :: sign_out()
54+ item <- try(suppressMessages(selectItem()), silent = TRUE )
55+ if (! is.null(item ) && ! inherits(item , " try-error" ))
56+ message(" Running item " , item )
57+ }
0 commit comments