0
我有一個關於R的Shiny問題。我有一個函數返回一個列表與2個對象作爲輸出,都作爲矩陣。第一個是始終創建的,並且始終可供下載。第二個,結合顯示爲複選框的條件。R閃亮:下載多個.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 matrizes,只有在第二個選項中顯示下載按鈕。 我有點困惑,因爲tableOutput
我在主面板中收到正確的表格,同時下載第一個下載部分的physical review
也能正常工作。 但第二個谷歌瀏覽器失敗,下載錯誤:
download_classify
Failed - Server problem
雖然它的構造相同的方式。
OH no,請原諒我的無能!是的,解決了我的問題.....非常感謝! –