Shiny on R과 관련된 문제가 있습니다. 두 객체가 출력되는 목록을 둘 다 매트릭스로 반환하는 함수가 있습니다. 첫 번째 파일은 항상 생성되며 항상 다운로드 할 수 있습니다. 두 번째는 확인란으로 표시된 조건과 결합됩니다.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 개의 matrizes를 반환하며 두 번째 옵션에서만 다운로드 버튼이 표시됩니다. tableOutput
과 함께 올바른 표가 표시되고 첫 번째 다운로드 부분이 제대로 작동하는 physical review
을 다운로드하기 때문에 약간 혼란 스럽습니다. 그러나 두 번째는 다운로드 오류와 구글 크롬에 실패는 같은 방법으로 제작 있어요하지만
download_classify
Failed - Server problem
합니다.
OH 아니요, 내 무능을 변명하십시오! 그래, 내 문제를 고쳤다 ..... 고마워! –