Я натолкнулся на эту ссылку https://rdrr.io/github/rstudio/shinytest/man/expectUpdate.html, где мы используем функцию waitUpdate для проверки блестящих входных и выходных данных. Я нашел странное поведение здесь. позволь мне объяснить. Я пытался реализовать expectUpdate
для 2 приложений. Но только для одного приложения это работает, а для другого - нет. Пожалуйста, обратитесь ниже 2 приложения. Любая указанная c причина, по которой он не работает для 2 приложений
ui.R - приложение 1 (где expectUpdate
работает)
# k-means only works with numerical variables,
# so don't give the user the option to select
# a categorical variable
vars <- setdiff(names(iris), "Species")
pageWithSidebar(
headerPanel('Iris k-means clustering'),
sidebarPanel(
selectInput('xcol', 'X Variable', vars),
selectInput('ycol', 'Y Variable', vars, selected = vars[[2]]),
numericInput('clusters', 'Cluster count', 3, min = 1, max = 9)
),
mainPanel(
plotOutput('plot1')
)
)
server.R - приложение 1 (где expectUpdate
работает)
function(input, output, session) {
# Combine the selected variables into a new data frame
selectedData <- reactive({
iris[, c(input$xcol, input$ycol)]
})
clusters <- reactive({
kmeans(selectedData(), input$clusters)
})
output$plot1 <- renderPlot({
palette(c("#E41A1C", "#377EB8", "#4DAF4A", "#984EA3",
"#FF7F00", "#FFFF33", "#A65628", "#F781BF", "#999999"))
par(mar = c(5.1, 4.1, 0, 1))
plot(selectedData(),
col = clusters()$cluster,
pch = 20, cex = 3)
points(clusters()$centers, pch = 4, cex = 4, lwd = 4)
})
}
функция waitUpdate для вышеуказанного приложения1 (Идеально)
app <- ShinyDriver$new("getwd()") # getwd() is the location of the project directory
expectUpdate(app, xcol = "Sepal.Width", output = "plot1")
## Getting no error
В то время как для приложения 2 ниже, waitUpdate не работает
shinyApp(
fluidPage(
numericInput("n", "Number to add", 5),
actionButton("add", "Add"),
verbatimTextOutput("sum", placeholder = TRUE)
),
function(input, output, session) {
nums <- numeric()
c_sum <- eventReactive(input$add, {
nums <<- c(nums, input$n)
sum(nums)
})
output$sum <- renderText({
c_sum()
})
}
)
ExpectUpdate ниже
app <- ShinyDriver$new(getwd())
expectUpdate(app, n = 5, add = 1, output = "sum")
Error: Updating ‘n’, ‘add’ did not update ‘sum’, or it is taking longer than 3000 ms.