'selectInput() in Shiny R not returning any values

I am trying to develop a Shiny app, a simple one. My intention at this point is to create a table and filter that table by various inputs. Right now this is my code:

library("shiny")
library("gapminder")
library("ggplot2")
library("colourpicker")
library("plotly")

ui <- fluidPage(
  h1("Demo"),
  sliderInput(inputId = "valor", label = "Rango ",
              min = min(data$value), max = max(data$value),
              value = c(min(data$value), max(data$value))),
  selectInput(inputId = "opc", label = "Measurements", choices = levels(data$measurement)),
  
  tableOutput("table")
)

server <- function(input, output) {
  output$table <- renderTable({
    data <- data
    data <- subset(
      data,
      value >= input$valor[1] & value <= input$valor[2]
    )
    data <- subset(
      data,
      measurement == input$opc
    )
    data
  })
}

levels(data$measurement)

shinyApp(ui, server)

as you can see, very simple. However, this code returns the table empty and the selectInput with no options of selection. However, if I put the values of the column by hand, the code works fine!

selectInput(inputId = "opc", label = "Measurements", choices = c("heart_rate","oxygen_saturation")),

The code above works great, the table suddenly displays data again and it filters correctly. I just don't get it! The sliderInput works great as well. The data set has been included as an enviroment variable. enter image description here

This are the two different outputs (first picture with written values, second picture using levels(data$measurement)): enter image description here

enter image description here

Why is this happening to me?!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source