user3022875
user3022875

Reputation: 9018

Tab names not appearing

I am trying to have content on 2 different tabs using shinydashboard so I use tabItems to put 2 tabItem but I do not see the tabs when I Run the app. Any idea how to see the tabs?

Also is there a way to attach the sidebar controls to the tabs? For example I have 2 tabs below Tab1 and tab2. Is it possible to only have the sidebar items with TabName = Tab1 appear when you are on tab 1?

Here is code you can run:

server.r

function(input, output,session) {

  output$Text<-renderUI({
#     if(is.null(input$Symbol) == FALSE)
#     {
     # browser()
      rows = length(ReactiveData())
      if(rows ==1 )
      { dat=c("a","")

      }else{
        dat=c("a","b","")
      }
      selectInput("Text", "select text:", c(dat,""),selected = "", multiple = TRUE)
#     }
  })

  ReactiveData<- reactive({

    return(rnorm((as.numeric(input$t)*as.numeric(input$b))))
  })


# output$plot1 <- renderPlot({
#   print("in plot 1")
#   plot(ReactiveData(),type='p', main = input$t)
# })

Reactivet<- reactive({
  return(as.numeric(input$t))
})

output$plot1 <- renderPlot({
  print("in plot 1")
  plot(ReactiveData(),type='p', main = Reactivet())
})



output$plot2<- renderPlot({
  print("in plot 2")
  plot(c(as.numeric(input$t)),type='b')
})

output$plot3<- renderPlot({
  print("in plot 3")
  plot(  as.numeric(input$Plot3Input),type='b')
})

  output$downloadData <- downloadHandler(

    filename = function() { 
      paste("test", '.csv', sep='') 
    },
    content = function(file) {
      write.csv(c(1,2,3,4), file)
    }
  )



}

ui.r

library(shinydashboard)


dashboardPage(skin="black",
  dashboardHeader(title = "Basic dashboard"),
  dashboardSidebar(
    sidebarMenu(
      menuItem(selectInput("b", "b:", c(1,2),selected = 1), tabName ="Tab1"),
      menuItem(selectInput("t", "t:", c(1,2),selected = 1), tabName ="Tab1"),
      menuItem(downloadButton('downloadData', label= 'Download', class= "mybutton"), tabName ="Tab1"),
      menuItem(uiOutput("Text"), tabName ="Tab1"),
      menuItem(selectInput("Plot3Input", "Input:", c(1,2,3,4,5,6),selected = 1), tabName ="Tab2")
    ),
       tags$head(tags$style(".mybutton{background-color:red;} .skin-black .sidebar .mybutton{color: green;}") )

    ),
#   dashboardBody(
#     # Boxes need to be put in a row (or column)
#     tabItems(
#                   tabItem(tabName = "Tab1", 
#                         fluidRow(
#                           column(width=6, 
#                                  box(plotOutput("plot1", height = 250))
#                           ),
#                           column(width=6, 
#                                  box(plotOutput("plot2", height = 250))
#                           )
#                         )
#                     ),
#                     tabItem(tabName = "Tab2",
#                       fluidRow(
#                         column(width=6, 
#                                box(plotOutput("plot3", height = 250))
#                         )
#                       )
#                     )
#             )
#   )#end dashboard

  dashboardBody(
    fluidRow(
      tabBox(
        title = "First tabBox",
        id = "tabset1", height = "400px",
        tabPanel("Tab1", box(plotOutput("plot1", height = 250)),
                 box(plotOutput("plot2", height = 250))),
        tabPanel("Tab2", plotOutput("plot3", height = 250)),width=11
      )
    )
  )

)

code to run app

library(shiny)
runApp("C://Users/me/pathtofolder")

Here is the output you can see that there no tabs:

enter image description here

Upvotes: 0

Views: 563

Answers (1)

vck
vck

Reputation: 837

Change your corresponding code block of ui.R with this:

dashboardBody(
  fluidRow(
    tabBox(
      title = "First tabBox",
      id = "tabset1", height = "400px",
      tabPanel("Tab1", box(plotOutput("plot1", height = 250)),
           box(plotOutput("plot2", height = 250))),
      tabPanel("Tab2", plotOutput("plot3", height = 250)),width=11
    )
  )
)

enter image description here

Upvotes: 0

Related Questions