This is the script I am trying to run, randomApp function is a wrapper for a simple shiny app. However, when I call randomApp() it throws me an error: Error: 'server' must be a function. It looks to me that the server is already a function so I have no idea why it gives me an error. Any ideas?
library(shiny)
randomUI <- function(id) {
tagList(
textOutput(NS(id, "val")),
actionButton(NS(id, "go"), "Go!")
)
}
randomServer <- function(id) {
moduleServer(id, function(input, output, session) {
rand <- eventReactive(input$go, sample(100, 1))
output$val <- renderText(rand())
})
}
randomApp <- function(){
ui <- fluidPage(
randomUI("random1"),
randomUI("random2"),
randomUI("random3")
)
server <- function(input, output, session) {
randomServer("random1")
randomServer("random2")
randomServer("random3")
}
runApp(ui, server)
}
randomApp()
>Solution :
You are using the wrong function to launch your app. You should use shinyApp rather than runApp when specifying a UI and server function. Check the help pages to see the difference.