RinteRface / shinydashboardPlus

extensions for shinydashboard
https://shinydashboardplus.rinterface.com
Other
449 stars 78 forks source link

Error: attempt to apply non-function #180

Open echoplaza opened 1 year ago

echoplaza commented 1 year ago

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

echoplaza commented 1 year ago

I have it working with the code here (below) but why is there a red "1" icon above the "Select page" dropdown?

library(shiny)
library(shinyWidgets)
library(shinydashboard)
library(shinydashboardPlus)

ui <- dashboardPage(
  header = dashboardHeader(
    title = "My Shiny App",
    leftUi = tagList(
      dropdownBlock(
        id = "menu",
        title = "Select page",
        icon = icon("list-alt"),
        selectInput("menu", label = NULL,
                    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")
    {
      box(title = "data box") 
    } else 
    {
      box(title = "viz box")
    }
  })
}

shinyApp(ui, server)