R闪亮:bs4Dash中的“默认”选项卡

时间:2019-03-22 03:34:18

标签: r shiny shinydashboard

是否可以使用bs4Dash R package?

选择启动时的默认标签

在使用闪亮仪表板时,我使用updateTabSetPanel在开始时设置了默认标签。

下面是可复制的示例,我希望名为“ start”的选项卡成为启动时选择的选项卡。

library(shiny)
library(bs4Dash)

shiny::shinyApp(
  ui = bs4DashPage(
    navbar = bs4DashNavbar(),
    sidebar = bs4DashSidebar(
      skin = "light",
      bs4SidebarMenu(
        bs4SidebarHeader("Main content"),
        bs4SidebarMenuItem(
          "Classic theme",
          tabName = "classic",
          icon = "desktop"
        ),
        bs4SidebarMenuItem(
          "Start with me",
          tabName = "start", # <---- start with me!
          icon = "map"
        )
      )
    ),
    controlbar = bs4DashControlbar(
      skin = "light"
    ),
    footer = bs4DashFooter(),
    title = "Classic theme",
    body = bs4DashBody(
      bs4TabItems(
        bs4TabItem(
          tabName = "classic",
          fluidRow(
            bs4Box(
              height = "600px",
              title = "Box 1"
            ),
            bs4Box(
              height = "600px",
              title = "Box 2"
            )
          )
        )
      )
    )
  ),
  server = function(input, output) {}
)

1 个答案:

答案 0 :(得分:1)

在Shiny会话初始化后,使用JavaScript手动选择选项卡:

tags$head(tags$script('
  $(document).on("shiny:sessioninitialized", function(event) {
    $(\'a[data-value="start"]\').tab("show");
  });
')),

您可以在bs4DashBody中加入此代码段。