Skip to content

Commit 7d5f1b0

Browse files
committed
Adaptation for config moved to BioDataScience
1 parent 6f8469e commit 7d5f1b0

File tree

17 files changed

+273
-159
lines changed

17 files changed

+273
-159
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Authors@R: c(
99
email = "guyliann.engels@umons.ac.be"))
1010
Maintainer: Philippe Grosjean <phgrosjean@sciviews.org>
1111
Depends: R (>= 3.3.0)
12-
Imports: learndown
12+
Imports: learndown, BioDataScience, shiny, miniUI
1313
Suggests: SciViews, ggplot2, ggpubr, data.io, flow, chart, covr, knitr, testthat, gradethis
1414
License: MIT + file LICENSE
1515
Encoding: UTF-8

NAMESPACE

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
export(config)
43
export(learnr_banner)
54
export(learnr_server)
65
export(learnr_setup)
76
export(run)
8-
export(sign_in)
9-
importFrom(learndown,config)
7+
export(run_app)
8+
export(update_pkg)
9+
importFrom(BioDataScience,config)
10+
importFrom(BioDataScience,sign_in)
11+
importFrom(BioDataScience,sign_out)
1012
importFrom(learndown,learndownLearnrBanner)
1113
importFrom(learndown,learndownLearnrServer)
1214
importFrom(learndown,run)
15+
importFrom(miniUI,gadgetTitleBar)
16+
importFrom(miniUI,miniContentPanel)
17+
importFrom(miniUI,miniPage)
18+
importFrom(miniUI,miniTitleBarButton)
19+
importFrom(miniUI,miniTitleBarCancelButton)
20+
importFrom(shiny,dialogViewer)
21+
importFrom(shiny,observeEvent)
22+
importFrom(shiny,runGadget)
23+
importFrom(shiny,selectInput)
24+
importFrom(shiny,stopApp)

NEWS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
## Changes in version 2020.0.0
44

5-
- Clean up. Now depends on learndown only.
6-
- `config()`, `sign_in()`, `learnr_setup()` and `learnr_banner()` functions
5+
- Clean up. Now depends on learndown and BioDataScience only.
6+
- `learnr_setup()` and `learnr_banner()` functions
77
added.
8+
- Tutorials and Shiny applications are reworked to use the {learndown} package.
89

910
## Changes in version 2019.11.0
1011

R/BioDataScience1-package.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#' @docType package
66
#' @name BioDataScience1-package
77
#'
8-
#' @importFrom learndown config run learndownLearnrBanner learndownLearnrServer
8+
#' @importFrom learndown run learndownLearnrBanner learndownLearnrServer
9+
#' @importFrom BioDataScience config sign_in sign_out
10+
#' @importFrom shiny dialogViewer observeEvent selectInput stopApp runGadget
11+
#' @importFrom miniUI gadgetTitleBar miniContentPanel miniPage miniTitleBarButton miniTitleBarCancelButton
912
NULL
1013

1114
#@importFrom BioDataScience init

R/addins.R

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# RStudio addins
2+
3+
run_addin <- function() {
4+
#library(shiny)
5+
#library(miniUI)
6+
7+
selectTutorial <- function() {
8+
tutorials <- dir(system.file("tutorials", package = "BioDataScience1"))
9+
if (!length(tutorials)) return(NULL)
10+
11+
ui <- miniPage(
12+
miniContentPanel(
13+
selectInput("tutorial", "Tutorials in BioDataScience1:",
14+
selectize = FALSE, size = 11, tutorials)
15+
),
16+
gadgetTitleBar("", left = miniTitleBarCancelButton(), right =
17+
miniTitleBarButton("done", "Select", primary = TRUE))
18+
)
19+
20+
server <- function(input, output, session) {
21+
observeEvent(input$done, {
22+
returnValue <- input$tutorial
23+
if (!is.null(returnValue))
24+
BioDataScience1::run(returnValue)
25+
stopApp(returnValue)
26+
})
27+
}
28+
29+
runGadget(ui, server,
30+
viewer = dialogViewer("Select a tutorial",
31+
width = 300, height = 250))
32+
}
33+
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() {
76+
# Update both BioDataScience & BioDataScience1
77+
learndown::update_pkg("BioDataScience",
78+
github_repos = "BioDataScience-course/BioDataScience")
79+
update_pkg()
80+
}
81+
82+
sign_out_addin <- function()
83+
BioDataScience::sign_out()

R/config.R

Lines changed: 0 additions & 71 deletions
This file was deleted.

R/learnr.R

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#' Prepare a learnr tutorial for learndown recording
2+
#'
3+
#' These functions add recording functionalities through the learndown approach.
4+
5+
#' @param cap The caption of learnr R code widgets.
6+
#' @param debug Do we issue debugging messages (by default, yes if the
7+
#' environment variables `LEARNDOWN_DEBUG` is not `0`).
8+
#'
9+
#' @export
10+
learnr_setup <- function(cap = "Code R",
11+
debug = Sys.getenv("LEARNDOWN_DEBUG", 0) != 0) {
12+
learndown::learndownLearnrSetup(config = BioDataScience::config(),
13+
sign_in = BioDataScience::sign_in(), cap = cap, debug = debug)
14+
}
15+
16+
#' @rdname learnr_setup
17+
#' @export
18+
#' @param simple Do we use a simple banner without title or not?
19+
learnr_banner <- function(simple = FALSE) {
20+
if (isTRUE(simple)) {
21+
learndownLearnrBanner(
22+
msg.nologin = 'Utilisateur anonyme, aucun enregistrement !',
23+
msg.login = 'Enregistrement actif pour ')
24+
} else {
25+
learndownLearnrBanner(
26+
title = "Science des donn\u00e9es biologiques\ I",
27+
text = "R\u00e9alis\u00e9 par le service d'\u00c9cologie num\u00e9rique, Universit\u00e9 de Mons (Belgique)",
28+
image = "https://wp.sciviews.org/BioDataScience-96.png",
29+
msg.nologin = 'Utilisateur anonyme, aucun enregistrement !',
30+
msg.login = 'Enregistrement actif pour ')
31+
}
32+
}
33+
34+
#' @rdname learnr_setup
35+
#' @export
36+
#' @param input The Shiny input.
37+
#' @param output The Shiny output.
38+
#' @param session The Shiny session.
39+
learnr_server <- function(input, output, session)
40+
learndownLearnrServer(input, output, session)

R/run.R

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,57 @@
1-
#' Run learnr tutorials from the BioDataScience1 package
1+
#' Run learnr tutorials, Shiny applications from the BioDataScience1 package, or
2+
#' update it
3+
#'
4+
#' Start a learnr tutorial or a Shiny application from the BioDataScience1
5+
#' package, possibly after updating it.
26
#'
37
#' @param tutorial The name of the tutorial to use. If not provided, a list of
48
#' available tutorials is displayed.
5-
#' @param ... Further arguments passed to `learnr::run_tutorial()`.
9+
#' @param app The name of the Shiny application to use. If not provided, a list
10+
#' of available applications is displayed.
11+
#' @param ... Further arguments passed to `learnr::run_tutorial()` or to
12+
#' `shiny::runApp()`.
613
#' @param update Do we check for an updated version first, and if it is found,
714
#' update the package automatically?
8-
#' @param ask In case `tutorial` is not provided, do we ask to select in a list?
9-
#'
10-
#' @description Start the learnr R engine in the current R session with the
11-
#' selected tutorial.
15+
#' @param ask In case `tutorial` or `app` is not provided, do we ask to select
16+
#' in a list?
17+
#' @param in.job Should the application be run in a Job in RStudio (`TRUE` by
18+
#' default)?
1219
#'
13-
#' @return If `tutorial` is not provided, in interactive mode with `ask = TRUE`,
14-
#' you have to select one in a list, and in non interactive mode, or
15-
#' `ask = FALSE`, it returns the list of all available tutorials.
20+
#' @return If `tutorial` or `app` is not provided, in interactive mode with
21+
#' `ask = TRUE`, you have to select one in a list, and in non interactive mode,
22+
#' or `ask = FALSE`, it returns the list of all available tutorials or Shiny
23+
#' applications in the BioDataScience1 package.
1624
#' @export
1725
#' @keywords utilities
18-
#' @concept run interactive learnr documents from the BioDataScience package
26+
#' @concept run interactive learnr or Shiny applications
1927
#' @examples
28+
#' \dontrun{
2029
#' # To start from a list of available tutorials:
2130
#' run()
22-
#' \dontrun{
23-
#' run("00a_learnr")
31+
#' # Idem for Shiny applications:
32+
#' run_app()
2433
#' }
2534
run <- function(tutorial, ..., update = ask, ask = interactive()) {
26-
#BioDataScience::init()
2735
if (missing(tutorial))
2836
tutorial <- NULL
2937
learndown::run(tutorial = tutorial, package = "BioDataScience1",
30-
repos = "BioDataScience-course/BioDataScience1", ..., update = update,
31-
ask = ask)
38+
github_repos = "BioDataScience-course/BioDataScience1",
39+
..., update = update, ask = ask)
3240
}
41+
42+
#' @rdname run
43+
#' @export
44+
run_app <- function(app, ..., update = ask, ask = interactive(),
45+
in.job = TRUE) {
46+
if (missing(app))
47+
app <- NULL
48+
learndown::run_app(app = app, package = "BioDataScience1",
49+
github_repos = "BioDataScience-course/BioDataScience1",
50+
..., update = update, ask = ask, in.job = in.job)
51+
}
52+
53+
#' @rdname run
54+
#' @export
55+
update_pkg <- function()
56+
learndown::update_pkg(package = "BioDataScience1",
57+
github_repos = "BioDataScience-course/BioDataScience1")

inst/rstudio/addins.dcf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Name: Run learnr tutorial
2+
Description: Run one of the learnr tutorials in this package (after possibly updating it)
3+
Binding: run_addin
4+
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/A02a_limits/app.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
learndown::learndownShinyVersion("0.0.9001") # Set app version
2-
BioDataScience1::config()
2+
BioDataScience::config()
33

44
library(shiny)
55
library(learndown)
@@ -45,7 +45,7 @@ server <- function(input, output, session) {
4545
})
4646

4747
trackEvents(session, input, output,
48-
sign_in.fun = BioDataScience1::sign_in)
48+
sign_in.fun = BioDataScience::sign_in)
4949
trackSubmit(session, input, output, max_score = 2, solution =
5050
list(limits_x = c(0, 100), limits_y = c(0, 40)),
5151
comment = "Choix des limits de x et y",

0 commit comments

Comments
 (0)