【发布时间】:2020-01-25 13:49:49
【问题描述】:
我正在尝试为我一直在开发的闪亮应用创建单元测试,但不知道如何为可编辑的 DT 表输入值。
示例应用:
library(shiny)
library(DT)
ui <- fluidPage(
DTOutput("table"),
textOutput("mean")
)
server <- function(input, output) {
tableUpdate <- reactiveVal(0)
table <- data.frame(A = 1:5, B = 6:10, C = 11:15)
output$table <- renderDT({table},
options = list(paging = FALSE, dom = 't'),
selection = 'none',
server = FALSE,
editable = list(target = 'row')
)
observeEvent(input$table_cell_edit, {
table <<- editData(table, input$table_cell_edit)
tableUpdate(tableUpdate() + 1)
})
output$mean <- renderText({
tableUpdate()
paste(mean(table$A), mean(table$B), mean(table$C))
})
}
shinyApp(ui, server)
示例测试:
library(shinytest)
app <- ShinyDriver$new(".")
app$setInputs(table_cell_clicked = list(row = 2, col = 2, value = 7), allowInputNoBinding_ = TRUE)
app$setInputs(table_cell_edit = data.frame(row = 2, col = 0:3, value = "1"),
allowInputNoBinding_ = TRUE, priority_ = "event", wait_ = FALSE, values_ = FALSE)
app$takeScreenshot()
app$stop()
rm(app)
当我记录测试时,我主要保留了它的输出方式,但我已经更正了 table_cell_edit 和 table_cell_clicked 的 setInputs 值(作为向量输出)。
这给出了错误:
Error in sd_getAllValues(self, private, input, output, export) :
Unable to fetch all values from server. Is target app running with options(shiny.testmode=TRUE?)
在测试模式下运行并不能解决问题。
【问题讨论】:
-
您的
app.R需要调整,未能成功编辑和存储已编辑的值。还有,要不要在app.R中定义table_cell_clicked,代码好像在那里找不到。