【问题标题】:Shiny Dashboard - Change Dashboard Body Based on Selected Tab闪亮的仪表板 - 根据选定的选项卡更改仪表板正文
【发布时间】:2021-10-06 03:15:15
【问题描述】:

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

    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)

【问题讨论】:

    标签: r shiny shinydashboard


    【解决方案1】:

    您可以将空白选项卡定义为第一个menuItem,然后您应该能够选择适当的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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-24
      • 2015-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-14
      相关资源
      最近更新 更多