Shinydashboars tabItems not working properly

喜你入骨 提交于 2019-12-12 01:47:25

问题


I am testing the shinydashboard package and I just can't figure out what is happening in a particular case. My dashboard has 4 tabItems (sorry it's in Dutch):

  • Programma
  • Deelnemers
  • Notulen
  • Overige

The dashboard loads properly, but the content of tabItem four ("Overige") is shown beneath the content of "Notulen".

The code of the App is as follows:

library(shiny)
library(shinydashboard)
library(markdown)
library(DT)


# Simple header -----------------------------------------------------------

header <- dashboardHeader(title="Economencongres")

# Sidebar --------------------------------------------------------------

sidebar <- ## Sidebar content
  dashboardSidebar(
    sidebarMenu(
      menuItem(
        "Programma 2015",
        tabName = "Programma",
        icon = icon("info-circle")
      ),
      menuItem(
        "Deelnemers",
        tabName = "Deelnemers",
        icon = icon("users")
      ),
      menuItem(
        "Notulen",
        tabName = "Notulen",
        icon = icon("file-text")
      ),
      menuItem(
        "Presentaties",
        tabName = "Presentaties",
        icon = icon("file-movie-o")
      )
    )
  )

# Compose dashboard body --------------------------------------------------

body <- dashboardBody(
  tabItems(
    # First tab content
    # Boxes need to be put in a row (or column)
    tabItem(
      tabName = "Programma",
      fluidRow(
        tabBox(
          width = 12,
          title = "",
          id = "tabset1", height = "250px",
          tabPanel(
            "Agenda",
            h2(""),
            width = 12,
            h2("Agenda d.d. 25-03-2015"),
            includeHTML("Agenda.html")
          ),
          tabPanel(
            "Presentatie ABN AMRO",
            h2("Danny van Brummelen"),
            tags$iframe(
            width="800",
            height="600",
            seamless="seamless",
            src="http://www.allmoocs.nl/wordpress/wp-content/uploads/2015/05/ABN.pdf"
            )
          ),
          tabPanel(
            "Presentatie HAN BKMER",
            h2("Witek ten Hove"),
            h4("Klik op de presentatie en navigeer met de pijlen op het toetsenbord"),
            tags$iframe(
            width="1000",
            height="800",
            seamless="seamless",
            src="http://witusj.github.io/Economencongres/economen25032015.html"
            )
          )
        ) # End of tabBox
      ) # End of fluidRow
    ), # End of tabItem

    # Second tab content
    # Boxes need to be put in a row (or column)
    tabItem(
      tabName = "Deelnemers",
      fluidRow(
        tabBox(
          width = 12,
          title = "",
          id = "tabset2", height = "250px",
          tabPanel("Kaart",
                   h2(""),
                   tags$iframe(
                     width="800",
                     height="600",
                     seamless="seamless",
                     src="http://www.allmoocs.nl/wordpress/wp-content/uploads/2015/05/map.html"
                   )
          ),
          tabPanel("Lijst",
                   DT::dataTableOutput('deeln')
          )
        ) # End of tabBox
      ) # End of fluidRow,
    ), # End of tabItem

    # Third tab content
    # Boxes need to be put in a row (or column)
    tabItem(
      tabName = "Notulen",
      fluidRow(
        box(
          h2(""),
          width = 12,
          includeMarkdown("txt10.md")
        ),
        box(
          h2(""),
          width = 12,
          includeMarkdown("txt11.md")
        ),
        box(
          h2(""),
          width = 12,
          includeMarkdown("txt12.md")
        )
      ) # End of fluidRow
    ), # End of tabItem

    # Fourth tab content
    # Boxes need to be put in a row (or column)
    tabItem(
      tabName = "Presentaties",
      fluidRow(
        box(
          h2("Hello")
        )
      ) # End of fluidRow
    ) # End of tabItem
  ) ## End tabItems
) ## End dashboardBody




# Setup Shiny app UI components -------------------------------------------

ui <- dashboardPage(header, sidebar, body, skin = "purple")

# Setup Shiny app back-end components -------------------------------------

server <- function(input, output) {

  source('map.R')
  output$deeln <- DT::renderDataTable({
    DT::datatable(ec[,c(2:8)])

 })
}


# Render Shiny app --------------------------------------------------------

shinyApp(ui, server)

Must be my ingnorance, but it's driving me nuts!

UPDATE: I cleaned up the code a bit, but the problem persists.


回答1:


I solved it! The problem seems to be caused by the .md files. I don't know why but they prevent the closure of the tabItem. The weird thing though is that it first seemed to work in the RStudio environment and now it doesn't. However after deployment on my AWS Shiny Server everything looks OK. Weird things are happening here!

library(shiny)
library(shinydashboard)
library(markdown)
library(DT)


# Simple header -----------------------------------------------------------

header <- dashboardHeader(title="Economencongres")

# Sidebar --------------------------------------------------------------

sidebar <- ## Sidebar content
  dashboardSidebar(
    sidebarMenu(
      menuItem(
        "Programma 2015",
        tabName = "Programma",
        icon = icon("info-circle")
      ),
      menuItem(
        "Deelnemers",
        tabName = "Deelnemers",
        icon = icon("users")
      ),
      menuItem(
        "Notulen",
        tabName = "Notulen",
        icon = icon("file-text")
      ),
      menuItem(
        "Presentaties",
        tabName = "Presentaties",
        icon = icon("file-movie-o")
      )
    )
  )

# Compose dashboard body --------------------------------------------------

body <- dashboardBody(
  tabItems(

    # First tab content
    # Boxes need to be put in a row (or column)
    tabItem(
      tabName = "Programma",
      fluidRow(
        box(
          width = 12,
          h2("Agenda d.d. 25-03-2015"),
          includeHTML("Agenda.html")
        ) 
      ) # End of fluidRow
    ), # End of tabItem

    # Second tab content
    # Boxes need to be put in a row (or column)
    tabItem(
      tabName = "Deelnemers",
      fluidRow(
        tabBox(
          width = 12,
          title = "",
          id = "tabset2", height = "250px",
          tabPanel("Kaart",
                   h2(""),
                   tags$iframe(
                     width="800",
                     height="600",
                     seamless="seamless",
                     src="http://www.allmoocs.nl/wordpress/wp-content/uploads/2015/05/map.html"
                   )
          ),
          tabPanel("Lijst",
                   DT::dataTableOutput('deeln')
          )
        ) # End of tabBox
      ) # End of fluidRow,
    ), # End of tabItem

    # Third tab content
    # Boxes need to be put in a row (or column)
    tabItem(
      tabName = "Notulen",
      fluidRow(
        box(
          h2(""),
          width = 12,
          includeMarkdown("txt10.md")
        ),
        box(
          h2(""),
          width = 12,
          includeMarkdown("txt11.md")
        ),
        box(
          h2(""),
          width = 12,
          includeMarkdown("txt12.md")
        )
      ) # End of fluidRow
    ), # End of tabItem

    # Fourth tab content
    # Boxes need to be put in a row (or column)
    tabItem(
      tabName = "Presentaties",
      fluidRow(
        tabBox(
          width = 12,
          title = "",
          id = "tabset1",
          height = "250px",
          tabPanel(
              "Presentatie ABN AMRO",
              h2("Danny van Brummelen"),
              box(
              tags$iframe(
                width="800",
                height="600",
                seamless="seamless",
                src="http://www.allmoocs.nl/wordpress/wp-content/uploads/2015/05/ABN.pdf"
              )
            )
          ),
          tabPanel(
              "Presentatie HAN BKMER",
              h2("Witek ten Hove"),
              h4("Klik op de presentatie en navigeer met de pijlen op het toetsenbord"),
              box(
              tags$iframe(
                width="1000",
                height="800",
                seamless="seamless",
                src="http://witusj.github.io/Economencongres/economen25032015.html"
              )
            )
          )
        ) # End of tabBox
      ) # End of fluidRow
    ) # End of tabItem
  ) ## End tabItems
) ## End dashboardBody




# Setup Shiny app UI components -------------------------------------------

ui <- dashboardPage(header, sidebar, body, skin = "purple")

# Setup Shiny app back-end components -------------------------------------

server <- function(input, output) {

  source('map.R')
  output$deeln <- DT::renderDataTable({
    DT::datatable(ec[,c(2:8)])

  })
}


# Render Shiny app --------------------------------------------------------

shinyApp(ui, server

)



来源:https://stackoverflow.com/questions/30421596/shinydashboars-tabitems-not-working-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!