Ich habe ein Problem in Bezug auf Shiny auf R. Ich habe eine Funktion, die eine Liste mit 2 Objekten als Ausgabe zurückgibt, beide als eine Matrix. Der erste wird immer erstellt und steht immer zum Download bereit. Der zweite wird mit einer Bedingung kombiniert, die als Kontrollkästchen angezeigt wird.R glänzend: Laden Sie mehrere CSV-Dateien
global
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:
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)
So wie Sie im Code sehen kann ich eine bedingte Download-Button für die Textklassifikation erwähnt, wenn Das Kontrollkästchen wird ausgelöst. Nach diesem TRUE/FALSE-Wert wird die Funktion physical_check
mit true oder false aufgerufen und gibt eine Matrix und NULL oder 2 Matrizen zurück und nur in der zweiten Option wird der Download-Button angezeigt. Ich bin ein wenig verwirrt, denn mit tableOutput
erhalte ich die richtigen Tabellen in der Hauptanzeige, auch das Herunterladen der physical review
mit dem ersten Download-Teil funktioniert gut. aber die zweite nicht in Google Chrome mit einem Download-Fehler:
download_classify
Failed - Server problem
Obwohl es die gleiche Art und Weise aufgebaut ist.
OH nein, entschuldige meine Inkompetenz! Ja, das hat mein Problem behoben ..... Vielen Dank! –