Skip to content

Commit d59a376

Browse files
committed
New addin
1 parent 0a30a7d commit d59a376

File tree

4 files changed

+34
-77
lines changed

4 files changed

+34
-77
lines changed

.Rbuildignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ FAQ.md
1212
Makefile
1313
.Rprofile
1414

15-
16-
data-raw
17-
data-raw/*
18-
1915
^.*\.Rproj$
2016
^\.Rproj\.user$
2117
^README.R?md$

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ added.
99

1010
- The datasets `biometry` and `biometrie` are moved to `BioDataScience`.
1111

12+
- RStudio addin.
13+
1214
## Changes in version 2019.11.0
1315

1416
- Tutorial 06b_mds

R/addins.R

Lines changed: 30 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,54 @@ run_addin <- function() {
44
#library(shiny)
55
#library(miniUI)
66

7-
selectTutorial <- function() {
8-
tutorials <- dir(system.file("tutorials", package = "BioDataScience1"))
9-
if (!length(tutorials)) return(NULL)
7+
selectItem <- function() {
8+
package <- "BioDataScience1"
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 BioDataScience1:",
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-
BioDataScience1::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 = "BioDataScience1"))
45-
if (!length(apps)) return(NULL)
46-
47-
ui <- miniPage(
48-
miniContentPanel(
49-
selectInput("app", "Shiny apps in BioDataScience1:",
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-
BioDataScience1::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 & BioDataScience1
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+
}

inst/rstudio/addins.dcf

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
Name: Run learnr tutorial
2-
Description: Run one of the learnr tutorials in this package (after possibly updating it)
1+
Name: Run sdd I tutorial or app
2+
Description: Run one of the learnr tutorials or Shiny applications in this package
33
Binding: run_addin
44
Interactive: true
5-
6-
Name: Run Shiny application
7-
Description: Run one of the Shiny applications in this package (after possibly updating it)
8-
Binding: run_app_addin
9-
Interactive: true
10-
11-
Name: Update
12-
Description: Update the package
13-
Binding: update_pkg_addin
14-
Interactive: true
15-
16-
Name: Sign out
17-
Description: Sign out current user
18-
Binding: sign_out_addin
19-
Interactive: true

0 commit comments

Comments
 (0)