0

For example, I have a dataframe mtcars I want to extract only the column values based on the variable choices in the selectinput.

Sample code:

shinyApp(
  ui = fluidPage(
    varSelectInput("variable", "Variable:", mtcars),
    verbatimTextOutput('data')
  ),
  server = function(input, output) {
   
    output$data <- renderText({
      mtcars$input$variable
    })
   
  }
)

Ex: mtcars$mpg

enter image description here

I want only to extract the mpg vector values: 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7 15.0 21.4

1 Answer 1

0

Try this

output$data <- renderText({
      paste(mtcars[[as.name(input$variable)]])
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.