Skip to content

Commit a6e7981

Browse files
2 parents 9fb44f1 + a717482 commit a6e7981

File tree

6 files changed

+47
-84
lines changed

6 files changed

+47
-84
lines changed

NEWS.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
## Changes in version 2020.0.0
44

5-
- update all tutorials with sciviews box 2020
5+
- Update all tutorials with SciViews Box 2020, and name change with B01Xa_name,
6+
with 'B' refers to second course, '01' to first module, 'X' being `L` for learnr
7+
or `S` for Shiny and 'a' the sequence in case there are several similar items in
8+
the same module.
9+
10+
- RStudio addins.
611

712
## Changes in version 2019.11.0
813

@@ -20,21 +25,20 @@
2025

2126
## Changes in version 2019.9.0
2227

23-
- New shiny app 04e_gompertz
28+
- New Shiny app 04e_gompertz
2429

2530
## Changes in version 2019.8.0
2631

27-
- shiny app 04c 04d
32+
- Shiny app 04c 04d
2833

2934
## Changes in version 2019.7.0
3035

31-
- shiny app 04a_michaelis_menten and 04b_exponent
36+
- Shiny app 04a_michaelis_menten and 04b_exponent
3237

3338
## Changes in version 2019.6.0
3439

3540
- Tutorial 03a_mod_lin finalized
3641

37-
3842
## Changes in version 2019.5.0
3943

4044
- Tutorial 02a_reg_multi finalized

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 = "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+
}

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 tutorial or app from BioDataScience2
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

inst/shiny/B01Sa_reglin/app.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ ui <- fluidPage(
2626
withMathJax(),
2727
p("$$y(x) = a \\ x + \\ b $$"),
2828
sliderInput("a", label = "a",
29-
value = 0, min = -5, max = 5, step = 0.5),
29+
value = 0, min = -5, max = 5, step = 0.5),
3030
sliderInput("b", label = "b",
31-
value = 0, min = -5, max = 5, step = 0.5),
31+
value = 0, min = -5, max = 5, step = 0.5),
3232
hr(),
3333
submitQuitButtons()
3434
),
@@ -54,8 +54,8 @@ server <- function(input, output, session) {
5454

5555
model_predict <- reactive({
5656
dplyr::mutate(model_data,
57-
y_predit = reglin(x, a = input$a, b = input$b),
58-
distance2 = (y_predit - y)^2
57+
y_predit = reglin(x, a = input$a, b = input$b),
58+
distance2 = (y_predit - y)^2
5959
)
6060
})
6161

Binary file not shown.

inst/shiny/B04Sb_exponent/app.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ server <- function(input, output, session) {
6060

6161
model_predict <- reactive({
6262
dplyr::mutate(model_data,
63-
y_predit = exponent(x, y0 = input$y0, k = input$k),
64-
distance2 = (y_predit - y)^2
63+
y_predit = exponent(x, y0 = input$y0, k = input$k),
64+
distance2 = (y_predit - y)^2
6565
)
6666
})
6767

0 commit comments

Comments
 (0)