title: How to change the data source which is used for a plot depending on the selected dropdown menu in R Shiny?
body: <p>My situation is the following that I import a csv dataset from IMDB into my small Shiny app. It contains in the respective columns the values for runtime, IMDB-Rating, gross, votes, Meta-Score Rating etc...</p>
  <p>I have in the UI-section a selectInput where the user can select the available columns as mentioned above.</p>
  <p>In the Server-Section (before my <code>output$graph &lt;- renderPlot(...)</code>) I want to describe/implement that the outputPlot changes depending on the selected column. I tried to solve it using observeEvent like this...</p>
  <pre><code>  observeEvent(~get(input$type) == &quot;Meta-Score&quot;, {ratings &lt;- moviesdb$Meta_score})
    observeEvent(~get(input$type) == &quot;IMDB-Rating&quot;, {ratings &lt;- moviesdb$IMDB_Rating})
    etc...
  </code></pre>
  <p>using the global operator <code>&lt;&lt;-</code>
  and even using some type of switch-case logic:</p>
  <pre><code>   x &lt;- reactive(~get(input$type))
     y &lt;- NULL
     test &lt;- switch(c(x),
                    &quot;Meta-Score&quot; = {(ratings &lt;- moviesdb$Meta_score)},
                    &quot;IMDB-Rating&quot; = {(ratings &lt;- moviesdb$IMDB_Rating)},
                    &quot;Film-Laufzeit&quot; = {(ratings &lt;- moviesdb$Runtime)})
  </code></pre>
  <p>I really appreciate any help/hints/tips or even mock-up code on how to solve this problem! Since yesterday I am googling but I just dont find any solution or question which seems to be similar to what I want to achieve.</p>
  <p>Example Code:</p>
  <pre><code>library(shiny)
  library(ggplot2)
  
  moviesdb &lt;- read.csv(&quot;imdb_top_1000.csv&quot;, header=TRUE)
  moviesdb &lt;- na.omit(moviesdb) #remove NA from data set
  
  ui &lt;- fluidPage(
    
    selectInput(
      inputId = &quot;type&quot;,
      label = &quot;choose type&quot;,
      choices = c(&quot;Meta-Score&quot;, &quot;Votes&quot;),
      selected = &quot;Meta-Score&quot;,
      multiple = FALSE,
      selectize = TRUE,
      width = NULL,
      size = NULL
    ), 
    
    sliderInput(inputId = &quot;num&quot;, label = &quot;sample size&quot;, value = 500, min = 0, max = 800, step = 10), 
    plotOutput(&quot;distribution&quot;),
    
  )
  
  
  server &lt;- function(input, output) {
    
    ratings &lt;- moviesdb$Meta_score
    # x &lt;- reactive(~get(input$type))
    # y &lt;- NULL
    # test &lt;- switch(c(x),
    #                &quot;Meta-Score&quot; = {(ratings &lt;- moviesdb$Meta_score)},
    #               &quot;Votes&quot; = {(ratings &lt;- moviesdb$No_of_Votes)},
    # y
  
    # observeEvent(ratings, {
    #   print(paste0(&quot;You have chosen: &quot;, ratings))
    # })
  
    
    output$distribution &lt;- renderPlot(
      {
        
        filmratingssample &lt;- (sample(ratings, input$num, replace = FALSE, prob = NULL))
        mean_films &lt;- mean(filmratingssample)
        films &lt;- data.frame(dnorm(filmratingssample, mean = mean_films, sd = 1, log = FALSE))
        
        ggplot(data = films) + aes(x=filmratingssample) +
          geom_histogram(aes(y=..density..), col = &quot;white&quot;, binwidth=1)
        
        
        
      })
  
  }
  
  shinyApp(ui = ui, server = server)
  </code></pre>
  <p>Dataset from <a href="https://www.kaggle.com/harshitshankhdhar/imdb-dataset-of-top-1000-movies-and-tv-shows" rel="nofollow noreferrer">here</a></p>
  <p>Data looks as followed:</p>
  <pre><code>Year    Runtime Meta_score  No_of_Votes Gross
  1994    142 min 85,00   2343110 28,341,469
  1972    175 min 84,00   1620367 134,966,411
  2008    152 min 75,00   2303232 534,858,444
  </code></pre>