2017-10-09 37 views
0

如果用戶忘記上傳標籤文件,我想展示一個modalDialog。但是,我的modalDialog從不出現。有什麼建議麼?謝謝!如何顯示一條消息,如果文件沒有上傳到R Shiny?

server.R:

function(input, output, session) { 

    # Read in labels 

    labels <- eventReactive (input$inFile2, { 
     ldata = read.csv(input$inFile2$datapath, header=input$header2) 
     return(ldata[, 1]) 
    }) 

    # Go to next tab only if labels are uploaded 

    observeEvent(input$act_next, { 
     if(nlevels(labels())> 0) { 
     updateTabsetPanel(session, "allResults", 'selVars') 
     } else { 
     #if(is.null(input$inFile2$size)) { 
      showModal(modalDialog(strong(h5("Please upload labels.")), easyClose = TRUE, footer = NULL))    
     #} 
     } 
    }) 
} 

ui.R:

fluidPage(title = "Segmentation App", theme = shinytheme("spacelab"), 

navbarPage("Segmentation", id = "allResults", 
    tabPanel(value ='inputData', title = 'Data Import', 
     verticalLayout(
       h4("Import labels for the independent variables"), 
       fileInput(inputId="inFile2", "Choose a CSV File", 
          accept = c(
          "text/csv", 
          "text/comma-separated-values,text/plain", 
          ".csv" 
         ) 
      ), 

       checkboxInput("header2", "Header", TRUE), 
       br(), 
       actionButton("act_next", strong("Next!")) 
     ) 
    ), 

    tabPanel(value ='selVars', title = 'Data Preparation', 
      verticalLayout(
      ) 
    ) 

) )一個CSV的

示例文件加載: enter image description here

回答

0

eventReactive在默認情況下會檢查其事件表達式是否爲req。如果文件尚未上傳,並且input$inFile2爲空,則在調用labels()之後,將不會評估進一步的反應表達式。所以模態代碼甚至不會運行。

你可以改變從eventReactivelabelsreactive,或指定在eventReactive ARGS ignoreNULL = FALSE。並且確保在input$inFile2爲空時返回null。

相關問題