我有一个关于在R上闪光的问题。我有一个函数,它返回一个包含两个对象作为输出的列表,这两个对象都是矩阵。第一个总是创建的,并且总是可以下载的。第二个与显示为复选框的条件相结合。
全局
physical_check <- function(file_path, x,y,z, classification)
input: String, int, int, int, boolean
output: list(matrix1 = result, matrix2 = rating)用户界面:
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,返回一个矩阵和NULL或2个矩阵,并且仅在第二个选项中显示download按钮。我有点困惑,因为使用tableOutput我会在主面板中接收到正确的表,而且使用第一个下载部分下载physical review也可以正常工作。但第二个在google chrome中失败了,出现了一个下载错误:
download_classify
Failed - Server problem尽管它是以同样的方式构建的。
发布于 2017-03-07 14:45:56
您忘了在qmethod参数中加上引号""。分类的下载处理程序应该是这样的:
output$download_classify <- downloadHandler(
filename = function() {
paste0("rating", ".csv")
},
content = function(file) {
write.table(
result()$rating,
file,
sep = ";",
col.names = NA,
qmethod = "double"
)
}
)https://stackoverflow.com/questions/42627918
复制相似问题