R闪亮的仪表板选项卡 [英] R shiny dashboard tabItems not apparing

查看:38
本文介绍了R闪亮的仪表板选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的ui.R和server.R.我不确定为什么dashboardBody中的标题没有显示.

Here's my ui.R and server.R. I'm not sure why the headers in dashboardBody don't show up.

server.R

shinyServer(function(input, output){
})

ui.R

dashboardPage(
  dashboardHeader(title = "Analysis"),
  dashboardSidebar(
    sidebarMenu(
      menuItem("Data Pull", tabName = "dataPull", icon = icon("database"),
        dateInput("startDateInput", "What is the starting date?", value = NULL, min = NULL, max = NULL, format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en"),
        dateInput("endDateInput", "What is the ending date?", value = NULL, min = NULL, max = NULL, format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en")
      ),
      menuItem("View Data", tabName = "dataView", icon = icon("table"),
               selectInput("dataViewSelectionInput", label = "Selection of Interest?", choices = c(1,2,3), multiple = TRUE),
               checkboxInput("dataViewAll", label = "View all pulled", value = TRUE)
               )
    )
  ),
  dashboardBody(
    tabItems(
     tabItem(tabName = "dataPull",
            h1("Data Selected")
     ),
     tabItem(tabName = "dataView",
             h2("Viewing Data")
     )
   )
  )
)

推荐答案

当前,仪表板似乎不允许切换到选项卡并使用下拉菜单,我在这里找到了解决方法:

Currently, the dashboard seems to disallow switching to a tab and using a dropdown menu, I found a fix for it here:

将此功能添加到您的UI或全局变量的开头:

add this function to the beginning of your UI, or your globals:

convertMenuItem <- function(mi,tabName) {
    mi$children[[1]]$attribs['data-toggle']="tab"
    mi$children[[1]]$attribs['data-value'] = tabName
    mi
}

然后您的ui文件变为:

then your ui file becomes:

ui.R

dashboardPage(
  dashboardHeader(title = "Analysis"),
  dashboardSidebar(
    sidebarMenu(
      convertMenuItem(menuItem("Data Pull", icon = icon("database"),
                               dateInput("startDateInput", "What is the starting date?", value = NULL, min = NULL, max = NULL, format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en"),
                               dateInput("endDateInput", "What is the ending date?", value = NULL, min = NULL, max = NULL, format = "yyyy-mm-dd", startview = "month", weekstart = 0, language = "en"), 
                               tabName = "dataPull"),
                      tabName="dataPull"),
      convertMenuItem(menuItem("View Data", icon = icon("table"),
                               selectInput("dataViewSelectionInput", label = "Selection of Interest?", choices = c(1,2,3), multiple = TRUE),
                               checkboxInput("dataViewAll", label = "View all pulled", value = TRUE),
                               tabName = "dataView"),
                      tabName="dataView")
    )
  ),
  dashboardBody(
    tabItems(
      tabItem(tabName = "dataPull",
              h1("Data Selected")
      ),
      tabItem(tabName = "dataView",
              h2("Viewing Data")
      )
    )
  )
)

之所以起作用,是因为menuitem中有一些默认行为,如果menuItem有子项,它将不会设置数据切换标签或数据值标签,因此我手动设置它们.(已编辑以删除错字)

This works because there is some default behavior in menuitem where if the menuItem has subitems, it won't set the data-toggle or data-value tags, so I set them manually. (Edited to remove a typo)

这篇关于R闪亮的仪表板选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆