Skip to content

Error: attempt to apply non-function #180

@echoplaza

Description

@echoplaza

I'm trying to get both the page and sidebar to change based on the selectInput using renderUI and uiOutput.

Here is a very simple reprex wherein the server's renderUI function operates based on the selectInput to render either a "data" or a "visualize" page and sidebar.

  library(shiny)
  library(shinydashboard)
  library(shinydashboardPlus)
  
  ui <- dashboardPage(
    header = dashboardHeader(
      title = "My Shiny App",
      tags$li(class = "dropdown",
              selectInput("menu", "Menu:",
                          choices = c("Data", "Visualize"),
                          selected = "Data"))
    ),
    sidebar = dashboardSidebar(
      uiOutput("sidebar_content")
    ),
    body = dashboardBody(
      uiOutput("page_content")
    )
  )
  
  server <- function(input, output) {
    output$sidebar_content <- renderUI({
      if (input$menu == "Data") {
        sidebarMenu(
          menuItem("Data Page", tabName = "data_page")
        )
      } else {
        sidebarMenu(
          menuItem("Visualize Page", tabName = "visualize_page")
        )
      }
    })
    
    output$page_content <- renderUI({
      if (input$menu == "Data") {
        tabItems(
          tabItem(tabName = "data_page",
                  fluidRow(
                    column(12,
                           h3("This is the Data page"),
                           p("Here you can view and edit your data.")
                    )
                  )
          )
        )
      } else {
        tabItems(
          tabItem(tabName = "visualize_page",
                  fluidRow(
                    column(12,
                           h3("This is the Visualize page"),
                           p("Here you can visualize your data.")
                    )
                  )
          )
        )
      }
    })
  }
  
  shinyApp(ui, server)

But running the App returns this error:
"Error in dashboardHeader(title = "My Shiny App", tags$li(class = "dropdown", :
attempt to apply non-function"

Any ideas? Should this be possible?

Thanks,

echo

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions