【发布时间】:2018-05-22 17:45:30
【问题描述】:
关于闪亮:
我希望几个人工编码员对 100 种不同的文本进行评分。 在每一页上都应该只有一个简单的下拉菜单,其中包含可用的评分。 我可以使用简单的“提交”按钮为单个页面/文本实现此功能,并将答案保存在单个 csv 文件中。
但现在我想对所有 100 个文本进行概括 - 这样每个页面都会显示一个新文本(我会将此作为 for 循环实现吗?)并希望将所有 100 个答案保存在一个 .csv 中 -文件。
我是 Shiny 的新手(但在 R 方面还不错),但找不到同时提供这两种功能的功能 - 多个页面和多个保存的输入。
我当前的单页代码如下所示(主要受https://deanattali.com/2015/06/14/mimicking-google-form-shiny 启发):
humanTime <- function() format(Sys.time(), "%Y%m%d-%H%M%OS")
fieldsMandatory <- c("new_info", "agreement", "rating")
fieldsAll <- c("new_info", "agreement", "rating")
responsesDir <- file.path("responses")
epochTime <- function() {
as.integer(Sys.time())
}
shinyApp(
ui = fluidPage(
shinyjs::useShinyjs(),
titlePanel("Kommentarbewertungen Spiegel Online - Pre-Test"),
mainPanel("This is the main panel"),
br(),
code(text[1]),
br(),
div(
id = "form", align="center",
selectInput("new_info", "Bringt der Kommentar neue Informationen ein?",
c("","0 - nein", "1 - ja", "2 - unentschlossen")),
selectInput("agreement", "Stimmen Sie dem Kommentar zu?",
c("","0 - nein", "1 - ja", "2 - unentschlossen")),
selectInput("rating", "Bewerten Sie die Qualitaet des Kommentars auf einer Skala von 1 bis 5",
c("","1 - sehr schlecht", "2 - schlecht", "3 - mittel", "4 - gut", "5 - sehr gut")),
actionButton("submit", "Submit", class = "btn-primary")
),
br(),
actionButton("prevBtn", "< Previous"),
actionButton("nextBtn", "Next >")
),
server = function(input, output, session) {
observe({
# check if all mandatory fields have a value
mandatoryFilled <-
vapply(fieldsMandatory,
function(x) {
!is.null(input[[x]]) && input[[x]] != ""
},
logical(1))
mandatoryFilled <- all(mandatoryFilled)
# enable/disable the submit button
shinyjs::toggleState(id = "submit", condition = mandatoryFilled)
})
formData <- reactive({
data <- sapply(fieldsAll, function(x) input[[x]])
data <- c(data, timestamp = epochTime())
data <- t(data)
data
})
saveData <- function(data) {
fileName <- sprintf("%s_%s.csv",
humanTime(),
digest::digest(data))
write.csv(x = data, file = file.path(responsesDir, fileName),
row.names = FALSE, quote = TRUE)
}
# action to take when submit button is pressed
observeEvent(input$submit, {
saveData(formData())
})
}
)
非常感谢。
【问题讨论】: