0

It is my understanding Shiny's selectInput widget returns a character vector. I am unclear as to why the user input cannot be passed to ggplot as a column name. Naturally this fails to plot as desired.

This is my yaml.

[![enter image description here][1]][1]

Blockquote --- title: "Untitled" output: flexdashboard::flex_dashboard: orientation: rows runtime: shiny



library(tidyverse)
library(flexdashboard)
library(shiny)



spy <- tibble(Date  = as.Date(c("2020-12-28", "2021-12-30", "2022-03-15")),
              Happy = c(8.25, 12.48, 11.52 ),
              Glad  = c(4, 5, 7 ) )

  

shiny::selectInput(
             inputId = "select_data",
             label   = "Select Data",
             choices = c("Happy", "Glad"),
             selected = "Happy"                             
   )

renderPlot({
  
   ggplot(spy, aes(   1:3,  input$select_data) )   +
     geom_line()

})






  [1]: https://i.stack.imgur.com/sHEWu.png
  [2]: https://i.stack.imgur.com/rIWrY.png
123blee
  • 87
  • 1
  • 7
  • 2
    Does this answer your question? [How to connect user input with gganimate graph in R shiny?](https://stackoverflow.com/questions/71810703/how-to-connect-user-input-with-gganimate-graph-in-r-shiny) – Limey May 01 '22 at 03:32
  • 2
    You can use the data pronoun: `renderPlot({ ggplot(spy, aes(x = Date, .data[[input$select_data]]) ) + geom_line() })` – jpdugo17 May 01 '22 at 03:38
  • 2
    `aes_string(...)` instead of `aes(...)` should work –  May 01 '22 at 07:12
  • All 3 worked! Thank you for the quick round of responses. - 1) !!sym(input$select_data])), 2) aes_string(...) , and 3) .data[[input$select_data]] – 123blee May 01 '22 at 17:40

0 Answers0