1

I am making a shiny app that interacts with a big data.frame that I have stored as an RData file. I want the user to select the file, and once the RData is completely loaded (takes ~15 seconds) a second panel should show up allowing the user to input some sample name and do some operations.

Here is how my app looks now

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)

I have used the solution provide in Make conditionalPanel depend on files uploaded with fileInput but I can't make it work, there is another implementation using shinyjs package but don't know how to use it on my example

Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
user2380782
  • 1,542
  • 4
  • 22
  • 60

0 Answers0