From f5060b6aee7dc2099bc8b51846c3c653e9396ae1 Mon Sep 17 00:00:00 2001 From: Radhika Khetani Date: Mon, 24 Mar 2025 13:06:41 +0100 Subject: [PATCH] small suggestions @Gammerdinger 1. "Do not run" comments for code that does not need to be run 2. parameter names initially for SelectInput(), i.e. "inputID =" and "label =" --- RShiny/lessons/03_visuals.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/RShiny/lessons/03_visuals.md b/RShiny/lessons/03_visuals.md index 5759650f..0b1ae3d6 100644 --- a/RShiny/lessons/03_visuals.md +++ b/RShiny/lessons/03_visuals.md @@ -21,11 +21,13 @@ library(DT) To render a data table on the UI side you would use: ``` +# Do Not Run DTOutput("outputID") ``` On the server side you would use: ``` +# Do Not Run output$ <- renderDT({ }) @@ -37,7 +39,7 @@ Let's use the built-in dataset `mtcars` to visualize an example of a data table # User interface ui <- fluidPage( # Checkbox group to select which columns we would like to see in the data table - checkboxGroupInput("column_input", "Select columns", choices = colnames(mtcars), inline = TRUE), + checkboxGroupInput(inputId = "column_input", label = "Select columns", choices = colnames(mtcars), inline = TRUE), # The output table DTOutput("table") ) @@ -80,12 +82,14 @@ The syntax for implementing plots is: On the UI side: ``` +# Do Not Run plotOutput("") ``` On the server side: ``` +# Do Not Run output$ <- renderPlot({ }) @@ -99,9 +103,9 @@ On the server side, we place ggplot2 code inside the `renderPlot()` function, sp # User Interface ui <- fluidPage( # Dropdown menu to select which column will be used for the x-axis - selectInput("x_axis_input", "Select x-axis", choices = colnames(mtcars)), + selectInput(inputId = "x_axis_input", label = "Select x-axis", choices = colnames(mtcars)), # Dropdown menu to select which column will be used for the y-axis - selectInput("y_axis_input", "Select y-axis", choices = colnames(mtcars), selected = "disp"), + selectInput(inputId = "y_axis_input", label = "Select y-axis", choices = colnames(mtcars), selected = "disp"), # The output plot plotOutput("plot") ) @@ -139,6 +143,7 @@ The first way that we can interact with a plot is by clicking a point on the plo On the UI side: ``` +# Do Not Run plotOutput("plot", click = "") ``` @@ -150,6 +155,7 @@ The `click = ""` argument allows for an input from the click actio On the server side, we have a few new functions as well: ``` +# Do Not Run output$table <- renderDT({ nearPoints(, input$) }) @@ -193,6 +199,7 @@ Instead of clicking on points in your plot, you can instead hover over them and On the UI side: ``` +# Do Not Run plotOutput("plot", hover = hoverOpts("", delay = 25)) ``` @@ -238,6 +245,7 @@ The last way that you can make your plots interactive is with brushing. Perhaps On the UI side: ``` +# Do Not Run plotOutput("plot", brush = "") ``` @@ -253,6 +261,7 @@ We can change `brush = ""` to `brush = brushOpt("")` On the server side we need to use: ``` +# Do Not Run output$table <- renderDT({ brushedPoints(, input$) })