闪亮的仪表板 - 根据选定的选项卡更改仪表板主体

Shiny Dashboard - Change Dashboard Body Based on Selected Tab

现在,当用户运行该应用程序时,会显示所需的 website/dashboard 正文,但是,我希望仅当用户 select 的“控件”时显示所需的 website/body侧边栏菜单中“选项卡 1”中的“图表”。这是因为我会有多个侧边栏选项卡,当根据用户 selects 的网站时,嵌入式网站应该会自动更改。当用户最初运行应用程序时,仪表板主体应该是空白的。只有当他们 select Tab 1 -> Cell Culture -> Control Chart 时,他们才能看到 google 主页。 请帮忙!

    ui <-
    dashboardPage(
        skin = "black",
        dashboardHeader(title = "Dashboard ", titleWidth = 450),
        dashboardSidebar(sidebarMenu(
            menuItem(
                "Tab 1",
                tabName = "tab 1",
                icon = icon("medicine"),
                menuItem("Cell Culture",
                         menuItem("Control Chart"))
            )
        )),
        
        dashboardBody(mainPanel(fluidRow(htmlOutput("frame"))
        ),
        
        ))

server = function(input, output, session) {
    observe({
        test <<- paste0("https://google.com") #sample url
    })
    output$frame <- renderUI({
        input$Member
        my_test <- tags$iframe(src = test,
                               height = 800,
                               width = 800)
        print(my_test)
        my_test
    })
}
shinyApp(ui, server)

您可以定义一个空白选项卡作为第一个 menuItem,然后您应该可以 select 适当的 menuItem 来显示所需的对象。此外,您应该定义 tabName 以确保显示适当的对象并将其绑定到 dashboardBody 中,如下所示。试试这个

ui <-
  dashboardPage(
    skin = "black",
    dashboardHeader(title = "Dashboard ", titleWidth = 450),
    dashboardSidebar(sidebarMenu(
      menuItem("",tabName="home"),
      menuItem(
        "Tab 1",
        tabName = "tab 1",
        icon = icon("medicine"),
        menuItem("Cell Culture",
                 menuItem("Control Chart", tabName = "mytab"))
      )
    )),
    
    dashboardBody(mainPanel(
      tabItems(
        tabItem(tabName = "home"),
        tabItem(tabName = "mytab",
                fluidRow(plotOutput("plot1"), htmlOutput("frame"))
        )
      )
      
    ),
    
    ))

server = function(input, output, session) {
  #observe({
  #  test <- paste0("https://google.com") #sample url
  #})
  output$plot1 <- renderPlot(plot(cars))
  url <- a("Google Homepage", href="https://www.google.com/")
  output$frame <- renderUI({
    #input$Member
    my_test <- tags$iframe(href = url,
                           height = 800,
                           width = 800)
    print(my_test)
    print("Hello!")
    my_test
  })
}
shinyApp(ui, server)