Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R Shiny: Error: `server` must be a function

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading