简体   繁体   English

在 Shiny 中检查 rhandsontable 中的有效输入

[英]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.

相关问题 在rhandsontable单元格中插入控件输入和HTML小部件 - Inserting control inputs and HTML widgets inside rhandsontable cells in shiny 在闪亮的模块中使用rhandsontable - Using rhandsontable in a shiny module 对自身具有反应性的闪亮的rhansontable - Shiny rhandsontable that is reactive to itself 在Shiny中使用Rhandsontable时出错 - Error using rhandsontable in Shiny 在 shiny 中编辑 rhandsontable - Edit rhandsontable in shiny r闪亮:从另一个可混音中更新可混音 - r shiny: updating rhandsontable from another rhandsontable 在 R Shiny 中,如何使用 actionButton 重置 rhandsontable 中的数据(反转所有手动输入)? - In R Shiny, how do you reset data (reversing all manual inputs) in rhandsontable using an actionButton? 在 R 中,如何将使用 rhandsontable 生成的表格和相关输入移动到模态对话框中? - In R shiny how to move table and related inputs, generated using rhandsontable, into a modal dialogue box? 如何通过单击 R shiny 中的操作按钮为用户输入反应生成额外的 rhandsontable 表? - How to reactively generate additional rhandsontable tables for user inputs with click of an action button in R shiny? 当使用用户输入响应式更新 Shiny 中的表时,如何对 rhandsontable 中的所有列求和? - How to sum all colums in rhandsontable when reactively updating the table in Shiny with user inputs?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM