From 3f0580e7c69892d6efd6c9cf65a5700fa8a79fa9 Mon Sep 17 00:00:00 2001 From: Joseph Tran <joseph.tran@inrae.fr> Date: Sat, 23 Mar 2024 17:14:40 +0100 Subject: [PATCH 1/4] add extra steps to run the tutorial in background keeping it alive while developping a new shiny application project --- README.md | 17 +++++++++++++++++ run_in_background.R | 1 + 2 files changed, 18 insertions(+) create mode 100644 run_in_background.R diff --git a/README.md b/README.md index 4900802..a2d8a80 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Shiny Tutorial +This shiny tutorial uses {learnr} package to create an interactive tutorial. The tutorial is designed to help you learn the basics of shiny within a shiny application. + ## Getting started 1. Clone this repository and open the `shiny-tutorial.Rproj` file in RStudio. @@ -15,4 +17,19 @@ install.packages(paks) 4. Execute the shiny tutorial using the button `Run the document` 5. Follow the steps and complete the exercises +## Run the tutorial in the background + +To be able to develop a shiny application alongside an active shiny tutorial, you need to follow some extra-steps: +1. Stop and close any previous shiny tutorial that is running +2. Create a new shiny project within RStudio +3. In the newly created shiny project, go to `Background jobs` tab and click on `Start background job` to create a new background job +4. Select `run_in_background.R` R script on clicking the `Browse` button +5. Select the `shiny-tutorial` folder as the working directory on clicking the `Browse` button +6. Click on `Start Job` to run the shiny tutorial in the background +7. Copy the returned URL mentioned after `Listening on ` string corresponding to this pattern `http://127.0.0.1:<port_number>` +8. Paste the URL in a new window browser to start the tutorial +9. Follow the steps and complete the exercises + - if you had already begun the tutorial, you can continue from where you left off (learnr keeps track of your progress) + - you may want to start over the tutorial if so click on `Start Over` button in the sidebar (`caution`: it will reset all your progress in the tutorial) +10. Continue working within the current shiny project diff --git a/run_in_background.R b/run_in_background.R new file mode 100644 index 0000000..fc790c0 --- /dev/null +++ b/run_in_background.R @@ -0,0 +1 @@ +rmarkdown::run("shiny_tutorial.Rmd") \ No newline at end of file -- GitLab From 8034606d921b8ee814020a4461d819d7aaeb7dad Mon Sep 17 00:00:00 2001 From: Joseph Tran <joseph.tran@inrae.fr> Date: Sun, 24 Mar 2024 22:44:04 +0100 Subject: [PATCH 2/4] add path to create a multiple file shiny web app in RStudio --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a2d8a80..23d642a 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ To be able to develop a shiny application alongside an active shiny tutorial, yo 1. Stop and close any previous shiny tutorial that is running 2. Create a new shiny project within RStudio + - `File -> New File -> Shiny Web App -> Multiple File` 3. In the newly created shiny project, go to `Background jobs` tab and click on `Start background job` to create a new background job 4. Select `run_in_background.R` R script on clicking the `Browse` button 5. Select the `shiny-tutorial` folder as the working directory on clicking the `Browse` button -- GitLab From 01d995ad5ce748dbccd829c90c2917b6623368cf Mon Sep 17 00:00:00 2001 From: Joseph Tran <joseph.tran@inrae.fr> Date: Sun, 24 Mar 2024 22:44:49 +0100 Subject: [PATCH 3/4] add quizz first draft --- shiny_tutorial.Rmd | 239 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 238 insertions(+), 1 deletion(-) diff --git a/shiny_tutorial.Rmd b/shiny_tutorial.Rmd index bae35df..b36e688 100644 --- a/shiny_tutorial.Rmd +++ b/shiny_tutorial.Rmd @@ -21,8 +21,245 @@ description: > library(learnr) ``` +## Shiny Quizz -## Introduction +### Shiny application/structure + +```{r shiny-quizz-0, echo=FALSE} +quiz( + question("Qu'est-ce que Shiny?", + answer("Un framework pour créer des applications web interactives avec R", correct = TRUE), + answer("Un espèce de pokémon rare"), + answer("Une crème contre les rayons bleus des écrans"), + answer("Un framework pour créer des applications web interactives avec Python", correct = TRUE) + ), + question("Combien de composants sont nécessaires pour créer une application Shiny ?", + answer("1"), + answer("2", correct = TRUE), + answer("3"), + answer("4") + ), + question("Quels sont les deux composants nécessaires pour créer une application Shiny ?", + answer("ui.R et server.R", correct = TRUE), + answer("ui.R et app.R"), + answer("server.R et app.R"), + answer("ui.R et ui.R") + ), + question("Quel est le composant qui permet de définir l'interface utilisateur dans une application Shiny ?", + answer("ui.R", correct = TRUE), + answer("server.R"), + answer("app.R"), + answer("ui.R et server.R") + ), + question("Quel est le composant qui permet de définir le serveur dans une application Shiny ?", + answer("server.R", correct = TRUE), + answer("ui.R"), + answer("app.R"), + answer("ui.R et server.R") + ) +) +``` + +### UI layout + +```{r shiny-quizz-1, echo=FALSE} +quiz( + question("En combien de colonnes est divisée une ligne dans une application Shiny ?", + answer("5"), + answer("8"), + answer("9"), + answer("12", correct = TRUE) + ), + question("Quelle fonction permet de créer une page avec une barre latérale dans une application Shiny ?", + answer("sidebarLayout", correct = TRUE), + answer("pageWithSidebar", message="déprécié, utiliser sidebarLayout"), + answer("pageWithFooter"), + answer("fluidPage") + ), + question("Quelle fonction permet de créer un layout multipage dans une application Shiny ?", + answer("navbarPage", correct = TRUE), + answer("tabsetPanel", correct = TRUE), + answer("navsetPanel", correct = TRUE), + answer("fluidPanel") + ), + question("Quelles sont les frameworks pour développer des dashboards en shiny?", + answer("shinydashboard", correct = TRUE), + answer("shinybootstrap"), + answer("shiny.semantic", correct = TRUE), + answer("bslib", correct = TRUE), + answer("bs4Dash", correct = TRUE) + ) +) +``` + +### UI input functions + +```{r shiny-quizz-2, echo=FALSE} +quiz( + question("Quelle fonction permet de créer un champ de texte dans une application Shiny ?", + answer("wordInput"), + answer("selectInput"), + answer("numericInput"), + answer("textInput", correct = TRUE) + ), + question("Quelle fonction permet de créer un menu déroulant dans une application Shiny ?", + answer("wordInput"), + answer("selectInput", correct = TRUE), + answer("numericInput"), + answer("textInput") + ), + question("Quelle fonction permet de créer un champ numérique dans une application Shiny ?", + answer("wordInput"), + answer("selectInput"), + answer("numericInput", correct = TRUE), + answer("textInput") + ), + question("Quelles sont les types d'input disponibles dans une application Shiny ?", + answer("text", correct = TRUE), + answer("numeric", correct = TRUE), + answer("date", correct = TRUE), + answer("box"), + answer("email", correct = TRUE), + answer("checkbox", correct = TRUE), + answer("radio", correct = TRUE), + answer("address"), + answer("file", correct = TRUE), + random_answer_order = TRUE + ), + question("Quelle fonction permet de créer un curseur numérique dans une application Shiny ?", + answer("sliderInput", correct = TRUE), + answer("selectInput"), + answer("numericInput"), + answer("textInput") + ) +) + +``` + +### Server rendering functions + +```{r shiny-quizz-3, echo=FALSE} +quiz( + question("Quelle est la fonction qui permet de générer un graphique dans une application Shiny ?", + answer("renderPlot", correct = TRUE), + answer("renderTable"), + answer("renderPrint"), + answer("renderDataTable") + ), + question("Quelle est la fonction qui permet de générer un tableau dans une application Shiny ?", + answer("renderTable", correct = TRUE), + answer("renderPlot"), + answer("renderPrint"), + answer("renderDataTable") + ), + question("Quelle est la fonction qui permet de générer un texte dans une application Shiny ?", + answer("renderPrint", correct = TRUE), + answer("renderTable"), + answer("renderPlot"), + answer("renderDataTable") + ), + question("Quelle est la fonction qui permet de générer un tableau dynamique dans une application Shiny ?", + answer("renderDataTable", correct = TRUE), + answer("renderTable"), + answer("renderPrint"), + answer("renderPlot") + ) +) + +``` + +### UI output functions + +```{r shiny-quizz-4, echo=FALSE} +quiz( + question("Quelle fonction permet de générer un graphique dans une application Shiny ?", + answer("plotOutput", correct = TRUE), + answer("tableOutput"), + answer("printOutput"), + answer("dataTableOutput") + ), + question("Quelle fonction permet de générer un tableau dans une application Shiny ?", + answer("tableOutput", correct = TRUE), + answer("plotOutput"), + answer("printOutput"), + answer("dataTableOutput") + ), + question("Quelle fonction permet de générer un texte dans une application Shiny ?", + answer("printOutput", correct = TRUE), + answer("tableOutput"), + answer("plotOutput"), + answer("dataTableOutput") + ), + question("Quelle fonction permet de générer un tableau dynamique dans une application Shiny ?", + answer("dataTableOutput", correct = TRUE), + answer("tableOutput"), + answer("printOutput"), + answer("plotOutput") + ) +) +``` + +### Expressions réactives + +```{r shiny-quizz-5, echo=FALSE} +quiz( + question("Quelle fonction permet de créer une dépendance entre une sortie et une autre expression dans une application Shiny ?", + answer("reactive", correct = TRUE), + answer("radioactive"), + answer("renderactive"), + answer("proactive") + ), + question("Quelle fonction reactive permet d'isoler une action dans une application Shiny ?", + answer("isolate", correct = TRUE), + answer("cache-cache"), + answer("lockdown"), + answer("iwanttobreakfree") + ), + question("Quelle fonction reactive permet de générer une dépendance à une seule variable dans une application Shiny ?", + answer("reactiveVal", correct = TRUE), + answer("reactiveValues", message = "reactiveValues() est une fonction qui permet de stocker plusieurs valeurs réactives"), + answer("reactorVal"), + answer("proactorValues") + ), + question("Quand peut-on utiliser la fonction observe() dans une application Shiny ?", + answer("Pour modifier un object reactiveValues", correct = TRUE), + answer("Pour déclencher l'affichage d'une fenêtre contextuelle", correct = TRUE), + answer("Pour envoyer un email"), + answer("Pour modifier un élément de l'interface utilisateur") + ), + question("Quelle(s) fonction(s) reactive permet(tent) de générer une dépendance à un évènement et d'éxécuter une action dans une application Shiny ?", + answer("observeEvent", correct = TRUE), + answer("observe"), + answer("eventReactive", correct = TRUE), + answer("observeInput"), + answer("reactiveEvent") + ) +) +``` + +### Déployer une application Shiny + +```{r shiny-quizz-6, echo=FALSE} +quiz( + question("Quelles sont les solutions existantes pour déployer une application Shiny ?", + answer("Shinyapps.io", correct = TRUE), + answer("Posit Connect", correct = TRUE), + answer("Shiny Server", correct = TRUE), + answer("Shiny Cloud") + ), + question("Quelle solution de déploiement utilise docker pour déployer une application Shiny ?", + answer("shinyproxy", correct = TRUE), + answer("Posit Connect"), + answer("Shiny Server"), + answer("SK8", correct = TRUE), + answer("binder", correct = TRUE), + answer("Hugging Face Spaces", correct = TRUE) + ) +) + +``` + +## Tutorial introduction ### Iris dataset -- GitLab From 4e50f34ebe7edd48932a04017b070c4d06ed8a05 Mon Sep 17 00:00:00 2001 From: Joseph Tran <joseph.tran@inrae.fr> Date: Mon, 25 Mar 2024 08:52:15 +0100 Subject: [PATCH 4/4] add binder configuration files --- install.R | 3 +++ runtime.txt | 1 + 2 files changed, 4 insertions(+) create mode 100644 install.R create mode 100644 runtime.txt diff --git a/install.R b/install.R new file mode 100644 index 0000000..17d240b --- /dev/null +++ b/install.R @@ -0,0 +1,3 @@ +install.packages("learnr") +install.packages("rmarkdown") +install.packages("DT") \ No newline at end of file diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..a26e672 --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +r-4.3-2024-01-10 \ No newline at end of file -- GitLab