将RData文件加载到Shinydashboard中时,使conditionalPanel出现

时间:2018-12-28 12:10:14

标签: r shiny shinydashboard shinyjs

我正在制作一个闪亮的应用程序,该应用程序可以与存储为RData文件的大data.frame进行交互。我希望用户选择文件,并在RData完全加载(约15秒)后出现另一个面板,允许用户输入一些样品名称并进行一些操作。

这是我的应用现在的外观

header <- dashboardHeader(title="Analysis and database")

sidebar <- dashboardSidebar(
   useShinyjs(),
   sidebarUserPanel(),
   hr(),
sidebarMenu(
# Setting id makes input$tabs give the tabName of currently-selected tab
id = "sidebarmenu",
menuItem("Analyse old data by Sample", tabName="oldfile", icon = icon("table"), startExpanded = FALSE),
fileInput(inputId = "file1", "Choose database file"),
    conditionalPanel(
    #condition = "input.sidebarmenu === 'oldfile'",
    condition = "output.fileUploaded == 'true' ",
    textInput(inputId = "sample", label ="Type a sample ID"),
    actionButton("go2", "Filter")
  )
 )
)

body <- dashboardBody(
 tags$style(type="text/css",
  ".shiny-output-error { visibility: hidden; }",
  ".shiny-output-error:before { visibility: hidden; }"),
tabItems(
  tabItem("oldfile", "Sample name data.table",
        fluidRow(DT::dataTableOutput('tabla_oldfile') %>% withSpinner(color="#0dc5c1")))
 )
)

  ui <- dashboardPage(header, sidebar, body)

### SERVER SIDE

server = function(input, output, session) {
  options(shiny.maxRequestSize=100000*1024^2)

prop <- reactive({

 if (input$go2 <= 0){
     return(NULL)
 }
 result <- isolate({
        if (is.null(input$file1))
            return(NULL)
        if (is.null(input$sample))
            return(NULL)
        inFile <- input$file1
        print(inFile$datapath)
        #big_df <- load(inFile$datapath)
        print (big_df)
        print(input$sample)
        oldtable <- big_df1 %>% filter_at(vars(GATK_Illumina.samples:TVC_Ion.samples), 
            any_vars(stringi::stri_detect_fixed(., as.character(input$sample))))
        oldtable
     })
 result
 })

output$fileUploaded <- reactive({
return(!is.null(prop()))
})
outputOptions(output, 'fileUploaded', suspendWhenHidden=FALSE)

output$tabla_oldfile <- DT::renderDataTable({

DT::datatable(prop(), 
              filter = 'top', 
              extensions = 'Buttons',
              options = list(
                dom = 'Blftip',
                buttons = 
                  list('colvis', list(
                    extend = 'collection',
                    buttons = list(list(extend='csv',
                                        filename = 'results'),
                                   list(extend='excel',
                                        filename = 'results'),
                                   list(extend='pdf',
                                        filename= 'results')),
                    text = 'Download'
                  )),
                scrollX = TRUE,
                pageLength = 5,
                lengthMenu = list(c(5, 15, -1), list('5', '15', 'All'))
              ), rownames = FALSE
    )
  })

 }
shinyApp(ui, server)

我使用了Make conditionalPanel depend on files uploaded with fileInput中提供的解决方案,但我无法使其工作,还有一个使用shinyjs包的实现,但是不知道如何在我的示例中使用它

0 个答案:

没有答案