ORIGINAL
ui <- fluidPage(
checkboxGroupInput('in1', 'Check some letters', choices = head(LETTERS)),
selectInput('in2', 'Select a state', choices = state.name, selected = NULL),
plotOutput('plot')
)
server <- function(input, output) {
output$plot <- renderPlot({
validate(
need(input$in1, 'Check at least one letter!'),
need(input$in2, 'Please choose a state.')
)
plot(1:10, main = paste(c(input$in1, input$in2), collapse = ', '))
})
}
shinyApp(ui, server)
what I tried but failed
req_para <- c("in1", "in2")
ui <- fluidPage(
checkboxGroupInput('in1', 'Check some letters', choices = head(LETTERS)),
selectInput('in2', 'Select a state', choices = state.name, selected = NULL),
plotOutput('plot')
)
server <- function(input, output) {
output$plot <- renderPlot({
validate(
unlist(lapply(req_para, function(i){
print(eval(parse(text = paste0("!is.null(input$",i,")"))))
need(parse(text = paste0("!is.null(input$",i,")")),paste0("please chosse ", i) )
})
))
plot(1:10, main = paste(c(input$in1, input$in2), collapse = ', '))
})
}
shinyApp(ui, server)