[英]Check rhandsontable for valid inputs in Shiny
Problem : I have the following sample app in which the user can make changes to an rhandsontable object.问题:我有以下示例应用程序,用户可以在其中更改 rhandsontable 对象。 I want to check if the modifications that the user is doing is valid.我想检查用户所做的修改是否有效。 Already implemented: If not valid, the cell color changes to dark red.已实现:如果无效,单元格颜色变为深红色。
Question: Is there a possibility to check in R (not only visually) the whole rhandsontable if it contains of only valid inputs, ie some TRUE/FALSE flag that can be returned and is an attribute of rhandsontable object or some hidden option or so?问题:是否有可能检查 R(不仅是视觉上)整个 rhandsontable 如果它只包含有效输入,即可以返回的一些 TRUE/FALSE 标志并且是 rhandsontable 对象的属性或一些隐藏选项等等?
library(shiny)
library(rhandsontable)
ui <- fluidPage(
rHandsontableOutput("table")
)
server <- function(input, output, session) {
output$table <- renderRHandsontable(
rhandsontable(mtcars)
)
observe({
str(input$table)
})
}
shinyApp(ui, server)
You can read in the table with hot_to_r
and then do the checks.您可以使用hot_to_r
读取表,然后进行检查。 In the example, if you change one cell to a character, the flag is set to FALSE
.在示例中,如果您将一个单元格更改为一个字符,则该标志设置为FALSE
。 This is because a character is returned as NA
in the input (I'm not sure why not the character is returned):这是因为字符在输入中作为NA
返回(我不确定为什么不返回该字符):
library(shiny)
library(rhandsontable)
ui <- fluidPage(
rHandsontableOutput("table"),
verbatimTextOutput("flag")
)
server <- function(input, output, session) {
# flag for numeric values
is_table_ok <- reactiveVal(FALSE)
output$table <- renderRHandsontable(
rhandsontable(mtcars)
)
observeEvent(input$table, {
table_object <- hot_to_r(input$table)
flag <- !is.na(table_object)
flag <- purrr::reduce(flag, `&&`)
is_table_ok(flag)
})
output$flag <- renderPrint({
is_table_ok()
})
}
shinyApp(ui, server)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.