2017-03-06 40 views
0

Shiny on Rに関する問題があります。出力として2つのオブジェクトを持つリストを両方とも行列として返す関数があります。最初のものは常に作成され、常にダウンロード可能です。もう1つは、チェックボックスとして表示される条件と組み合わせられます。R shiny:複数の.csvファイルをダウンロード

グローバル

physical_check <- function(file_path, x,y,z, classification) 
input: String, int, int, int, boolean 
output: list(matrix1 = result, matrix2 = rating) 

UI:

ui <- fluidPage( 
    # Application title 
    titlePanel("Review"), 

    # Sidebar with a slider input for number of bins 
    sidebarLayout(
    sidebarPanel(
     fileInput('file1', 'Choose .txt File', 
       accept=c('text/csv','text/comma-separated,text/plain')), 
     hr(), 

     checkboxInput("classification", "Use Text-Classification", value = FALSE), 
     hr(), 

     downloadButton("download_physic", "Physical Review"), 
     br(), 
     conditionalPanel(condition = "input.classification == true", 
         downloadButton("download_classify", "Text Classification")) 

    ), 
    mainPanel(
     h3("Review"), 
     tableOutput("rating"), 
     tableOutput("result_shiny") 
    ) 
    ) 

) 

サーバー:あなたは、私はテキスト分類のための条件付きのダウンロードボタンを言及したコードで見ることができるように

server <- function(input, output) { 
    inFile <- reactive({ 
    input$file1 
    }) 
    result <- reactive({NULL}) 

    classify <- reactive({ 
    input$classification 
    }) 

    observe({ 
    if (!is.null(inFile())) { 
     result <- reactive({ 
     withProgress({ 
      setProgress(message = "Processing review...") 
      physical_check(as.String(inFile()$datapath),15,8,3,classify()) 
     }) 
     }) 
    } 

    output$result_shiny <- renderTable({ 
    result()$result 
    }) 
    output$rating <- renderTable({ 
    result()$rating 
    }) 

    output$download_physic <- downloadHandler(
    filename = function() { 
     sub(pattern = "\\.txt",replacement = "_result.csv",inFile()$name) 
    }, 
    content = function(file) { 
     write.table(
     result()$result, 
     file, 
     sep = ";", 
     col.names = NA, 
     qmethod = "double" 
    ) 
    } 
) 

    output$download_classify <- downloadHandler(
    filename = function() { 
     paste("rating", ".csv") 
    }, 
    content = function(file) { 
     write.table(
     result()$rating, 
     file, 
     sep = ";", 
     col.names = NA, 
     qmethod = double 
    ) 
    } 
) 
    }) 
} 
# Run the application 
shinyApp(ui = ui, server = server) 

、もしチェックボックスがトリガされます。 このTRUE/FALSEの値によれば、関数physical_checkはtrueまたはfalseで呼び出され、行列とNULLまたは2つの行列が返され、2番目のオプションでのみダウンロードボタンが表示されます。 tableOutputでメインパネルに正しい表が表示され、physical reviewをダウンロードして最初のダウンロード部分がうまく動作するため、ちょっと混乱します。 しかし、もう一つはダウンロードエラーでグーグルクロームに失敗:それは同じように構築されていますが、

download_classify 
Failed - Server problem 

を。

答えて

0

qmethod引数に「""」という引用符を入れていないのを忘れてしまった。

output$download_classify <- downloadHandler(
     filename = function() { 
     paste0("rating", ".csv") 
     }, 
     content = function(file) { 
     write.table(
      result()$rating, 
      file, 
      sep = ";", 
      col.names = NA, 
      qmethod = "double" 
     ) 
     } 
    ) 
+0

OHいいえ、私の無能な人です!ええ、それは私の問題を修正した.....多くのありがとう! –

関連する問題