Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions R/app-driver-upload-file.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ app_upload_file <- function(
"shinytest2.outputValuesWaiter.start(", toJSON_atomic(timeout_), ", 2);"
))


filename <- inputs[[1]]
self$log_message(paste0("Uploading file for id: ", filename))
self$log_message(paste0("Uploading file(s) for id: ",
paste(filename, collapse = ", ")))

node_id <- app_find_node_id(self, private, input = names(inputs)[1])

Expand All @@ -42,7 +42,7 @@ app_upload_file <- function(
)

self$get_chromote_session()$DOM$setFileInputFiles(
files = list(fs::path_real(filename)),
files = as.list(fs::path_real(filename)),
nodeId = node_id
)

Expand Down
21 changes: 21 additions & 0 deletions tests/testthat/apps/upload-multi/app.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
library(shiny)

ui <- fluidPage(
"Upload multiple files:",
fileInput("files", label = NULL, multiple = TRUE),
verbatimTextOutput("file_out"),
)

server <- function(input, output) {

# Display `file` output
output$file_out <- renderPrint({
if (is.null(input$files))
return(NULL)
df <- input$files
df$datapath <- paste0("<tempdir>/", basename(df$datapath))
df
})
}

shinyApp(ui, server)
1 change: 1 addition & 0 deletions tests/testthat/apps/upload-multi/tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shinytest2::test_app()
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"input": {
"files": {
"name": [
"cars.csv",
"cars_2.csv"
],
"size": [
308,
229
],
"type": [
"text/csv",
"text/csv"
],
"datapath": [
"0.csv",
"1.csv"
]
}
},
"output": {
"file_out": " name size type datapath\n1 cars.csv 308 text/csv <tempdir>/0.csv\n2 cars_2.csv 229 text/csv <tempdir>/1.csv"
},
"export": {

}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions tests/testthat/apps/upload-multi/tests/testthat/cars.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"speed","dist"
4,2
4,10
7,4
7,22
8,16
9,10
10,18
10,26
10,34
11,17
11,28
12,14
12,20
12,24
12,28
13,26
13,34
13,34
13,46
14,26
14,36
14,60
14,80
15,20
15,26
15,54
16,32
16,40
17,32
17,40
17,50
18,42
18,56
18,76
18,84
19,36
19,46
19,68
20,32
20,48
20,52
20,56
20,64
22,66
23,54
24,70
24,92
24,93
24,120
25,85
38 changes: 38 additions & 0 deletions tests/testthat/apps/upload-multi/tests/testthat/cars_2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
"speed","dist"
4,2
4,10
7,4
7,22
8,16
9,10
10,18
10,26
10,34
11,17
11,28
12,14
12,20
12,24
12,28
13,26
13,34
13,34
13,46
14,26
14,36
14,60
14,80
15,20
15,26
15,54
16,32
16,40
17,32
17,40
17,50
18,42
18,56
18,76
18,84
19,36
19,46
1 change: 1 addition & 0 deletions tests/testthat/apps/upload-multi/tests/testthat/setup.R
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
shinytest2::load_app_env()
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
library(shinytest2)

test_that("Make sure upload can use two local files", {
app <- AppDriver$new(name = "upload-multi")

app$upload_file(files = c("cars.csv", "cars_2.csv"))
app$expect_values()

expect_error(
app$upload_file(files = "missing_file.csv"),
"Error finding upload file at path", fixed = TRUE
)
})