Unable to display multiple outputs in different tabs in R shiny

I want to display multiple outputs in 3 different tabs.But its throwing me an error and unable to move ahead as a result of same.i have tried debugging but nothing concrete so far.Can anyone please help as i am new to shiny.

library(shiny)
library(ggplot2)
library(dplyr)

Define UI for application that draws a histogram

ui <- fluidPage(

# Application title
titlePanel("Unisim Report"),

# Sidebar with a slider input for number of bins 
sidebarLayout(
    sidebarPanel(
        selectInput("Region1","Max Usage Hours Per Region:Select Region",max_usage_hours_per_region$Region,multiple=TRUE),
        
        selectInput("Region2","Mean Usage Hours Per Region:Select Region",mean_usage_hours_per_region$Region,multiple=TRUE),
        
        selectInput("Region3","Total Usage Hours Per Region:Select Region",sum_usage_hours_per_region$Region,multiple=TRUE),
        
        selectInput("Month1","Max Usage Hours Per Month:Select Month",max_usage_hours_per_month$Month,multiple=TRUE),
        
        selectInput("Month2","Mean Usage Hours Per Month:Select Month",mean_usage_hours_per_month$Month,multiple=TRUE),
        
        selectInput("Month3","Total Usage Hours Per Month:Select Month",sum_usage_hours_per_month$Month,multiple=TRUE),
        
        selectInput("Region","Select Region(s)", unique(df3_machine_region$Region), multiple=TRUE)
        
    ),
    
    # Show a plot of the generated distribution
    mainPanel(
        tabsetPanel(
            tabPanel(("Max usage hours per region",tableOutput("table1"))
                     ("Min usage hours per region",tableOutput("table2"))
                     ("Mean usage hours per region",tableOutput("table3"))
                     ("Max usage hours per month",tableOutput("table4"))
                     ("Min usage hours per month",tableOutput("table5"))
                     ("Mean usage hours per month",tableOutput("table6"))),
            tabPanel("Top 10 Machines per region and month",tableOutput('table7')),
            tabPanel("Usage Hours per Region",plotOutput("Plot1"))
        ) 
        
    )
)

)

Define server logic required to draw a histogram

server <- function(input, output) {

output$table1 <- renderTable(
    max_usage_hours_per_region[max_usage_hours_per_region$Region %in% input$Region1,])
output$table2 <- renderTable(
    mean_usage_hours_per_region[mean_usage_hours_per_region$Region %in% input$Region2,])
output$table3 <- renderTable(
    sum_usage_hours_per_region[sum_usage_hours_per_region$Region %in% input$Region3,])
output$table4 <- renderTable(
    max_usage_hours_per_month[max_usage_hours_per_month$Month %in% input$Month1,])
output$table5 <- renderTable(
    mean_usage_hours_per_month[mean_usage_hours_per_month$Month %in% input$Month2,])
output$table6 <- renderTable(
    sum_usage_hours_per_month[sum_usage_hours_per_month$Month %in% input$Month3,])
output$table7 <- renderTable(top_10_by_month_region_server_sort)

data <- reactive({
    if (is.null(input$Region)) {
        df3_machine_region
    } else {
        df3_machine_region %>% filter(Region %in% input$Region)
    }
})
output$Plot1 <- renderPlot({
    data() %>%
        ggplot(aes(x=Region, sum_as_hours)) +
        geom_bar(stat="identity", fill="steelblue")+
        theme_minimal()
})

}

Run the application

shinyApp(ui = ui, server = server)

Error in parse(file, keep.source = FALSE, srcfile = src, encoding = enc) :
C:\Users\Documents\R\Test\Unisim_Shiny_GUI/app.R:42:55: unexpected ','
41: tabsetPanel(
42: tabPanel(("Max usage hours per region",
^

Do you intend 9 or 3 tabPanels ? seems to be some confusion in the code around that.

Its 3 tabpanels.1st tab panel consists of multiple outputs,2nd and 3rd tab panel consist of 1 output each.

Then for that first panel, you need to give a single title, and then some form of container, to hold the multiples.
perhaps this pattern?


library(shiny)

ui <- fluidPage(
  mainPanel(
    tabsetPanel(
      tabPanel("tab1", tabsetPanel(
                                   tabPanel("subpanel1",p("text1_sub1")),
                                   tabPanel("subpanel2",p("text1_sub2")))),
      tabPanel("tab2", p("text2")),
      tabPanel("tab3", p("text3"))
    )
  )
)

server <- function(input, output, session) {
}

shinyApp(ui, server)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.