Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: attempt to apply non-function #180

Open
echoplaza opened this issue Feb 27, 2023 · 1 comment
Open

Error: attempt to apply non-function #180

echoplaza opened this issue Feb 27, 2023 · 1 comment
Labels
question Further information is requested

Comments

@echoplaza
Copy link

echoplaza commented Feb 27, 2023

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

@DivadNojnarg DivadNojnarg added the question Further information is requested label Feb 28, 2023
@echoplaza
Copy link
Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants