3

I am new to shiny dashboards and I am trying my hand at making a simple dashboard. I am trying to put together a dashboard that will basically go through different clustering algorithms and show how they work.

I have a menu item for the overall branching topic, and then input items within those menus that specify the parameters for the clustering algorithms.

My issue is I cannot get any output on my screen. I cannot render plots of even see the title for the boxes that I placed inside the tabItems. This seems to happen when I place a sub-item inside one of my menu items. I am not sure why.

Attached is my ui.R script and server.R script.

ui.R file: ui.R file

server.R file:

server.R file

Any help with this matter would be much appreciated.

Melanie Palen
  • 2,645
  • 6
  • 31
  • 50

1 Answers1

6

So, as far as I can see, the problem is due to the fact that you placed the radioButtons within the menuItem. If you want to only show the radioButtons when the tab kclustering is active, you need to wrap radioButtons in a conditionalPanel. It would look something like that:

library(shinydashboard)

ui <- dashboardPage(
   dashboardHeader(title = "Bla"),
   dashboardSidebar(
     sidebarMenu(
       id = "tabs",
       menuItem(
         "K-clustering",
         tabName = "kclustering",
         icon = icon("cogs")),
       conditionalPanel(
         "input.tabs == 'kclustering'",
         radioButtons("technique", "Technique Choice", 
                 c("K-Means" = "kmeans",
                   "K-Medians" = "kmedians",
                   "K-Medoids" = "kmedoids"),
                 select = "kmedians")
         ),
       menuItem("DBSCAN", tabName = "dbscan")
     )
 ),
 dashboardBody(
   tabItems(
     tabItem("kclustering",
       fluidRow(
         box(plotOutput("step1"))
       ))
      )
))

server <- function(input, output) {

  output$step1 <- renderPlot({

    hist(rnorm(5000))

  })

}

runApp(shinyApp(ui, server))

In this case, it's important to set the id argument of the sidebarMenu object to be able to formulate your condition. Bottom line is: don't put your radioButtons, sliderInput and textInput inside the menuItem objects but in the sidebarMenu object itself.

jess
  • 534
  • 2
  • 7