From e88f23624078249c016192f7998522da492770d2 Mon Sep 17 00:00:00 2001
From: Joseph Tran <joseph.tran@inrae.fr>
Date: Tue, 19 Mar 2024 16:09:12 +0100
Subject: [PATCH 1/2] update and reformat

---
 shiny_tutorial.Rmd | 49 +++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 3 deletions(-)

diff --git a/shiny_tutorial.Rmd b/shiny_tutorial.Rmd
index e79e71d..d49ae15 100644
--- a/shiny_tutorial.Rmd
+++ b/shiny_tutorial.Rmd
@@ -1,7 +1,20 @@
 ---
 title: "Développement d'une application Shiny"
-output: learnr::tutorial
+author:
+  - name: "Amandine Velt"
+    orcid: "0000-0002-3287-0786"
+    affiliations: "SVQV"
+  - name: "Joseph Tran"
+    orcid: "0000-0002-4624-0363"
+    affiliations: "EGFV"
+date: "2024-03-19"
+output:
+  learnr::tutorial:
+    progressive: true
+    allow_skip: true
 runtime: shiny_prerendered
+description: >
+  Learn how to build a shiny application.
 ---
 
 ```{r setup, include=FALSE}
@@ -9,14 +22,44 @@ library(learnr)
 ```
 
 
-### Introduction
+## Introduction
 
 Pour le tutoriel, nous allons utiliser un jeu de données intégré à R, nommé Iris. Il recense les tailles de pétales et de sépales pour un ensemble d'individus "iris" de trois espèces différentes, setosa, versicolor et virginica.
 
-Exécuter le code, bouton `Run code`, suivant pour afficher les premières lignes du jeu de données:
+Exécuter le code suivant, bouton `Run code`, pour afficher les premières lignes du jeu de données:
 
 ```{r iris, exercise=TRUE}
 head(iris)
 ```
 
 
+## Base d'une application Shiny
+
+La base de notre application Shiny de départ est comprise dans deux fichiers obligatoires au fonctionnement d'une application Shiny, `ui.R` et `server.R`.
+
+### ui.R
+
+Voici un exemple de `ui.R` que nous allons utiliser.
+
+```{r ui_R, exercise=TRUE}
+# k-means only works with numerical variables,
+# so don't give the user the option to select
+# a categorical variable
+vars <- setdiff(names(iris), "Species")
+
+pageWithSidebar(
+  headerPanel('Iris k-means clustering'),
+  sidebarPanel(
+    selectInput('xcol', 'X Variable', vars),
+    selectInput('ycol', 'Y Variable', vars, selected = vars[[2]]),
+    numericInput('clusters', 'Cluster count', 3, min = 1, max = 9)
+  ),
+  mainPanel(
+    tabsetPanel(type = "tabs",
+                tabPanel("Plot", plotOutput('plot1')),
+                tabPanel("Summary", verbatimTextOutput("summary")),
+                tabPanel("Table", tableOutput("table"))
+    )
+  )
+)
+```
-- 
GitLab


From 1d3017e11714951d7062f3cd7e20367715bdbb3c Mon Sep 17 00:00:00 2001
From: Joseph Tran <joseph.tran@inrae.fr>
Date: Tue, 19 Mar 2024 16:29:11 +0100
Subject: [PATCH 2/2] example of exercise chunk with solution

---
 shiny_tutorial.Rmd | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/shiny_tutorial.Rmd b/shiny_tutorial.Rmd
index d49ae15..8f04bdb 100644
--- a/shiny_tutorial.Rmd
+++ b/shiny_tutorial.Rmd
@@ -63,3 +63,36 @@ pageWithSidebar(
   )
 )
 ```
+
+### server.R
+
+Exemple de fichier server.R vide : 
+
+```{r server_R, exercise=FALSE, eval=FALSE}
+function(input, output, session) {
+
+}
+```
+
+Il s'agit maintenant de remplir le fichier server.R pour obtenir des résultats dans les tabPanel "Plot", "Summary" et "Table".  
+
+### Générer un tableau dynamique avec reactive({})
+
+Créer une reactive avec reactive({}) pour générer un tableau dynamique récupérant les 2 colonnes correspondant aux variables X et Y sélectionnées par l’utilisateur sur les données iris et ranger ce tableau dans une variable « selectedData »
+
+```{r server_R_selected_data, exercise=TRUE}
+function(input, output, session) {
+
+}
+```
+
+```{r server_R_selected_data-solution}
+function(input, output, session) {
+  
+  # Combine the selected variables into a new data frame
+  selectedData <- reactive({
+    iris[, c(input$xcol, input$ycol)]
+  })
+}
+```
+
-- 
GitLab