title: How can I select a specific column from a data frame in R using selectInput?
body: <p>I would like to select the options from the drop-down list, which are stored as different attributes in my data frame and use the slider to change the years, so that I could see its effect on the valueCard. Where I am stuck is, to find out, how the pf_rol attribute can be called from df1 data-frame to reflects its value on valueCard. </p>
  
  <p>I have successfully created 2 value cards already which can be manipulated by just a slider, but now I want to use the slider and the selectInput to change the values in ValueCard 'pfrol'.</p>
  
  <p>PS: Would really appreciate if someone help with a cartogram. I have all the names of the countries and would like to manipulate the different attributes along with sliders to observe changing trends just like value cards.</p>
  
  <p>global.r</p>
  
  <pre><code>df &lt;-   read.csv("hfi_cc_2018.csv", header = T)
  
  summary(df)
  sapply(df, function(x) sum(is.na(x)))
  #Replace Null Values
  df[is.na(df)] &lt;- 0
  df[,5:ncol(df)] &lt;- round(df[,5:ncol(df)], 2)
  
  #adding selective columns new df1
  #https://stackoverflow.com/questions/10085806/extracting-specific-columns-from-a-data-frame
  df1&lt;-  df[, (names(df) %in% c("year","countries","region","pf_rol", "pf_ss_homicide","pf_ss_disappearances_violent",    
  ))]
  </code></pre>
  
  <p>ui.r</p>
  
  <pre><code>require(shiny)
  require(shinydashboard)
  
  shinyUI(
  
    dashboardPage( 
      dashboardHeader(title = "Human Freedom Index", titleWidth = 300),
      dashboardSidebar(
        sliderInput("years","Select Year:",
                    min = min(df1$year),
                    max = max(df1$year),
                    value = min(df1$year),
                    step = 1),
        selectInput("variable","Select Freedom Factor:",
                    choices = list("Rule of Law"= "pf_rol",
                                   "Homicides Reported" = "pf_ss_homicide")
                    )
      ),
  
      dashboardBody(
          fluidRow(
          valueBoxOutput("pfrol"),  
          valueBoxOutput("pfrank"),
          valueBoxOutput("efrank")
        ),
        fluidRow(
          box(plotlyOutput("plot1"), width=15, height=400)
        )
      )
    )
  
  )
  </code></pre>
  
  <p>server.r</p>
  
  <pre><code>require(shiny)
  require(dplyr)
  require(shinydashboard)
  
  shinyServer(function(input,output){
  
     observe({
       (card &lt;- df1 %&gt;%
        filter(year == input$years))
      output$pfrank = renderValueBox(
        valueBox(round(mean(card$pf_score),1),
                 "Personal Freedom Score")
      )
  
    })  
  
  observe({
  
     if(input$variable == "Rule of Law"){
       if(filter(df1$year == input$years)){
         output$pfrol = renderValueBox(
           valueBox(round(mean(df1$pf_rol),1),
                    "Rule of Law")
         )
       }
  
     }
  
  })
  
  })
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/VhwNR.png" alt="output image below"></p>