R Shining-如何测试fileInput()
我试图编写测试,以检查闪亮的函数R Shining-如何测试fileInput(),r,shiny,R,Shiny,我试图编写测试,以检查闪亮的函数fileInput()是否正确读取文件。 我的问题是,我不知道在session$setInputs()中写什么才能从系统中获取文件 以下是一个示例应用程序: library(shiny) ui <- fluidPage( tagList( fileInput("file", "Please upload a file"), tableOutput("text") ) )
fileInput()
是否正确读取文件。
我的问题是,我不知道在session$setInputs()
中写什么才能从系统中获取文件
以下是一个示例应用程序:
library(shiny)
ui <- fluidPage(
tagList(
fileInput("file", "Please upload a file"),
tableOutput("text")
)
)
server <- function(input, output, session){
file <- reactive({input$file})
output$text <- renderTable({
req(file())
read.csv(file()$datapath)
})
}
shinyApp(ui, server)
我认为这与以下事实有关:
fileInput()
将文件上载到一个临时文件夹,然后返回到一个数据帧,您可以在其中获取数据路径,但我无法模拟此过程以使测试工作正常我有与您相同的问题,我做了一些调查,但找不到任何使用testServer或TestThis测试fileInput的方法。我找到的最佳解决方案是在使用shinytest软件包的recordTest()录制测试时拍摄快照来测试fileInput。很抱歉这么晚才回答。
我在rstudio的论坛上问了同样的问题,得到了答案
它的基本功能是将文件的数据路径设置为列表:
address <- "path/to/text.csv"
testServer(server, { session$setInputs(file= list(datapath = address)) })
地址
address <- "path/to/text.csv"
testServer(server, { session$setInputs(file= list(datapath = address)) })