I want to write an app that reads in the uploaded data, then puts enough numericInput
due to the number of unique elements in a column (the name of the columns is Big). This question here helped me.
The code is as below:
library(shiny)
ui <- fluidPage(
fileInput(inputId = "up","", accept = '.csv'),
uiOutput("sliders")
)
server <- function(input, output, session) {
INPUT <- reactive({
infile <- input$up
#validate(need(input$up, "Input a valid filepath."))
read.csv(infile$datapath, header = TRUE, sep = ",")
})
inVars <- reactive({
unique(INPUT()$Big)
})
output$sliders <- renderUI({
pvars <- length(inVars())
lapply(seq(pvars), function(i) {
numericInput(inputId = paste0("range", pvars[i]),label = pvars[i],value = 1)
})
})
}
shinyApp(ui = ui, server = server)
Three questions:
1. When I put
if (is.null(infile))
return(NULL)
instead of validate
, it gives me an error which looks like this:
missing value where TRUE/FALSE needed
What should I do to get rid of this error?
2. How could I add a label for each one of the numericInput
?
3. How could I use the input values later? In a reactive
environment?
Thanks