Tabs in Shiny Dashboard are not displaying graphics properly

shiny
rstudio
shinydashboard

#1

I am trying to create a shiny dashboards, that have two tabs. First tab (named dashboard) shows two graphs, and the other one (named widgets) is intended to show the first graph as is (from the first graph) and below it is supposed to show rpivottable. Problem is that the moment i add graphs/rpivottable to the second tab, all the display is vanished. here is the sample code:

library(shiny)
library(shinydashboard)
library(rhandsontable)
library(writexl)
library(readxl)
library(stringr)
library(ggplot2)
library(rpivotTable)

ui <- dashboardPage(skin = 'green',

  dashboardHeader( title = "Test", titleWidth = 280),
  dashboardSidebar(width = 280,  
  sidebarMenu(
  menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard")),
  menuItem("Pivot", tabName = "widgets", icon = icon("th"))

  )),

  dashboardBody(
  tabItems(
  # First tab content
  tabItem(tabName = "dashboard",
  fluidRow(
  column(5, 'Mpg Table') ), 
  br(), 
  fluidRow(
  rHandsontableOutput ('mpg')),
  br(),
  fluidRow(
  column(5,'mtcars Summary')),
  br(),
  fluidRow(
  column(3),column(6, tableOutput ('mtcars')),column(3))

  ),
  # Second tab content
  tabItem(tabName = "widgets",
  fluidRow(
  column(5,'Mpg table')),

  br(),

  fluidRow(
  rHandsontableOutput ('mpg')),

  br(),

  fluidRow(
  rpivotTableOutput('pivot')  
  )

  )
    )
      )
        )

server <- shinyServer(function(input, output) {

  #mpg
  output$mpg <- renderRHandsontable ({ rhandsontable({
   mpg[1,]  })
    })

  #mtcars

  output$mtcars <-renderTable ({  
   head(mtcars)})

 # pivot table

  output$pivot <- renderRpivotTable({ rpivotTable(mtcars)})


})

shinyApp(ui, server)

I figured that the moment I take away the "Second tab content" , dashboard starts displaying the first tab content , but when i add the second tab content back, neither first nor second tab works. Any idea why it is happening and how to fix it ?

Thanks


#2

Hi, you can't have two HTML elements with the same id on the same page (including all tabs). So having rHandsontableOutput('mpg') twice is the problem (I think...).

Cheers
Steen


#3

Thank you, it is as you explained