首页 > 解决方案 > 在shinydashboard中加载RData文件时出现条件面板

问题描述

我正在制作一个闪亮的应用程序,它与我存储为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 中提供的解决方案依赖于使用 fileInput 上传的文件,但我无法使其工作,还有另一个使用shinyjs包的实现,但不知道如何在我的示例中使用它

标签: rshinyshinydashboardshinyjs

解决方案


推荐阅读