检查 rhandsontable 在 Shiny 中的有效输入
Check rhandsontable for valid inputs in Shiny
问题:我有以下示例应用程序,用户可以在其中更改 rhandsontable 对象。我想检查用户所做的修改是否有效。已实施:如果无效,单元格颜色变为深红色。
问题:如果 Rhandsontable 仅包含有效输入,是否有可能检查整个 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)
您可以阅读 table 和 hot_to_r
,然后进行检查。在示例中,如果将一个单元格更改为一个字符,则标志设置为 FALSE
。这是因为在输入中返回了一个字符 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)
问题:我有以下示例应用程序,用户可以在其中更改 rhandsontable 对象。我想检查用户所做的修改是否有效。已实施:如果无效,单元格颜色变为深红色。
问题:如果 Rhandsontable 仅包含有效输入,是否有可能检查整个 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)
您可以阅读 table 和 hot_to_r
,然后进行检查。在示例中,如果将一个单元格更改为一个字符,则标志设置为 FALSE
。这是因为在输入中返回了一个字符 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)