如何创建一个动态的Rshiny面板

时间:2016-02-09 22:48:48

标签: r dynamic shiny

我是Rshiny的新手,如何在侧边栏中创建动态面板? 我这样做但它不起作用 如果还有其他建议吗?     库(有光泽)

shinyUI(fluidPage(theme="style.css",

  # Application title
  titlePanel("RNAseq app R "),
  sidebarLayout(
    sidebarPanel(
    fileInput('file1', 'Choose file to upload',
              accept = c(
                'text/csv',
                'text/comma-separated-values',
                'text/tab-separated-values',
                'text/plain',
                '.csv',
                '.tsv'
              )
    ),
    tags$hr(),

    navlistPanel(

      tabPanel("Quality Control"),
      tabPanel("Trimming"),

      tabPanel("Alignement")


    )
  )

,

    mainPanel(
      )
    ))) 

服务器

library(shiny)

shinyServer(function(input, output) {


})

1 个答案:

答案 0 :(得分:1)

您可以使用conditionalPanel来执行此操作,在我的示例中,我也使用shinydashboard,因为它更好

rm(list = ls())
library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(title = "Basic Dashboard"),
  dashboardSidebar(
    sidebarMenu(id="menu1",
                menuItem("Panel 1", tabName = "name1", icon = icon("th")),
                menuItem("Input A file", tabName =  "name2", icon = icon("th")),
                conditionalPanel(
                  condition = "input.menu1 == 'name2'",
                  fileInput('file1', 'Choose file to upload',
                            accept = c('text/csv', 'text/comma-separated-values', 'text/tab-separated-values','text/plain', '.csv','.tsv')),
                  selectInput("slider_test", "Some Dynamic Slider", choices = list("Years" = 1, "Months" = 2))
                ),
                menuItem("Panel 3", tabName = "name1", icon = icon("th"))
    )
  ),
  dashboardBody())
server <- function(input, output) {}
shinyApp(ui, server) 

enter image description here

修改:使用shinyBS

上传弹出式窗口
rm(list = ls())
library(shiny)
library(shinydashboard)
library(shinyBS)

ui <- dashboardPage(
  dashboardHeader(title = "Basic Dashboard"),
  dashboardSidebar(
    sidebarMenu(id="menu1",
                menuItem("Panel 1", tabName = "name1", icon = icon("th")),
                menuItem("Input A file", tabName =  "name2", icon = icon("th")),
                bsButton("upload", label = "Upload A file", block = TRUE, style="success"),
                bsModal("upload_popup", "Upload a File", "upload", size = "small",
                        fileInput('file2', 'Choose file to upload',accept = c('text/csv', 'text/comma-separated-values', 'text/tab-separated-values','text/plain', '.csv','.tsv')),
                        bsButton("some_button", label = "Do Something Else", block = TRUE, style="success"))
    ),
    conditionalPanel(
      condition = "input.menu1 == 'name2'",
      fileInput('file1', 'Choose file to upload',
                accept = c('text/csv', 'text/comma-separated-values', 'text/tab-separated-values','text/plain', '.csv','.tsv')),
      selectInput("slider_test", "Some Dynamic Slider", choices = list("Years" = 1, "Months" = 2))
    )
  ),
  dashboardBody())
server <- function(input, output) {}
shinyApp(ui, server) 

enter image description here