R Shiny:根据侧边栏选择显示/隐藏主面板选项卡面板

时间:2020-03-22 02:46:22

标签: r shiny

这是我的代码:

# Install and load packages
#install.packages("pacman")
library("pacman")
pacman::p_load(shiny,
               shinythemes  ) 

# Load databases

# The user interface of the app ----------------------------------------------------------
ui = fluidPage(
  titlePanel("My Title"),
  title = "Name et al. 2020",
  tags$h6("Authors: Author name"),
  sidebarLayout(sidebarPanel(width = 3,
                             radioButtons("omicInput", "1a. Explore by Dataset, or",
                                          choices = c("WC",
                                                      "EV", 
                                                      "Sec", 
                                                      "N-Glyco" ),
                                          selected =NULL),

                             selectInput("geneInput", "1b. Gene name", 
                                         choices = c("gene1", 
                                                     "gene2", 
                                                     "gene2" ), multiple = TRUE,
                                         selected =NULL),

                             selectInput("networkInput", "2. My network",
                                         choices = c("Combined",
                                                     "4 hours",
                                                     "Day 1", 
                                                     "Day 2" ),
                                         selected =NULL),

                             textAreaInput("textInput", "3. Explore paths between Genes (one gene per row)", width = "50%", height = "100%"), verbatimTextOutput("value"),

                             selectInput("datasetInput", "4. Download datasets",
                                         choices = c("Combined",
                                                     "4 hours",
                                                     "Day 1", 
                                                     "Day 2" ),
                                         selected =NULL),
                             downloadButton("downloadData", "Download")),

                mainPanel(id = "mainpanel_1",
                          tabsetPanel(id = "tab_panel_1",
                                      type = "tabs",
                                      tabPanel("Table 1", br(), tableOutput("table")),
                                      tabPanel("Expression profile", value="tab_panel_1", br(), plotOutput("plot")),
                                      tabPanel("Expression heatmap", br(), plotOutput("plot"))),
                          tabsetPanel(id = "tab_panel_2",
                                      type = "tabs",
                                      tabPanel("Table 2", br(), tableOutput("table")),
                                      tabPanel("Reduction", value="tab_panel_1", br(), plotOutput("plot")),
                                      tabPanel("Expansion", br(), plotOutput("plot"))) 
                          )
                )
  )

server <- function(input, output) {

}

shinyApp(ui, server)

我要显示侧边栏元素1a和1b的tab_panel_1。同样,我想显示侧边栏元素2和3的tab_panel_2,同时隐藏另一个元素。

我该如何实现?我只是从Shiny(我的第一次尝试)开始,所以我们将不胜感激。谢谢。

0 个答案:

没有答案