【发布时间】:2022-12-02 23:05:20
【问题描述】:
我正在使用这个包 (shinySurveys),我可以很容易地使用它。我面临一个关于 radioMatrixInput 对象的问题。除非所有选项都已完成,否则我似乎无法从对象中得到响应,这是我的挑战,用户可以留下一些未回答的选项。因此,如果问题有 4 个选项,他可以回答 2 个并留下 2 个,而不为他们选择一个选项。
我正在提供我正在描述的行为的示例。我试过 observe 和 observeEvent 但都没有用。
if (interactive()) {
df <- data.frame(
question = c(rep("I love sushi.", 3), rep("I love chocolate.",3), rep("I love vegetables.",3)),
option = c(rep(c("Disagree", "Neutral", "Agree"), 3)),
input_type = c(rep("matrix", 9)),
# For matrix questions, the IDs should be the same for each question
# but different for each matrix input unit
input_id = c(rep("matId", 9)),
dependence = NA,
dependence_value = NA,
required = FALSE
)
library(shiny)
library(shinySurveys)
ui <- fluidPage(
surveyOutput(df),
verbatimTextOutput('debug01')
)
server <- function(input, output, session) {
renderSurvey()
observe({
print(input$matId)
})
output$debug01 <- renderPrint({input$matId})
observeEvent(input$submit, {
print(input$matId)
showModal(modalDialog(
title = "Congrats, you completed your first shinysurvey!",
"You can customize what actions happen when a user finishes a survey using input$submit."
))
})
}
shinyApp(ui, server)
}
只要我提供所有选项的答案,这就可以正常工作。当我只选择一个选项时,该对象不会将任何答案返回给我在服务器中的打印功能。
你们中有人碰巧知道如何从闪亮的服务器部分访问该数据吗?
【问题讨论】:
标签: r shiny shiny-reactivity