2017-10-09 4 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:負荷にCSVファイルの

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(
      ) 
    ) 

) )

例:

enter image description here

答えて

0

eventReactiveは、デフォルトでイベント式を確認します(req)。ファイルがまだアップロードされておらず、input$inFile2がヌルの場合、labels()が呼び出された後で、さらなる反応式は評価されません。したがって、モーダルコードは実行されません。

eventReactivereactiveに変更するか、eventReactive argsにignoreNULL = FALSEを指定してください。 input$inFile2がnullの場合はnullを返すようにしてください。

関連する問題