在 R shiny 中如何将使用 rhandsontable 生成的 table 和相关输入移动到模态对话框中?

In R shiny how to move table and related inputs, generated using rhandsontable, into a modal dialogue box?

我对 rhandsontable 包和 R shiny 中模态对话框的使用非常陌生,但是在模态对话框中呈现反应式 tables 对模型类型非常重要我运行。我需要学习如何做好这件事!

下面的 MWE 生成一个简单的反应式 table,其工作方式类似于我经常使用的 table 类型,例如。当 运行ning 时,如何将当前显示在“显示”操作按钮下方的所有项目移动到模式对话框中?

下面的图片也显示了我正在尝试做的事情。

MWE 代码:

library(shiny)
library(rhandsontable)

ui <- shinyUI(fluidPage(
  h4("Click ´Show´ button below to trigger modal dialogue:"),
  
  actionButton("show","Show"),
  br(),br(),
  
  actionButton(inputId = "reset_input", label = "Reset"),
  br(),br(),
  
  rHandsontableOutput("two_by_two"),
  br(),
  
  tableOutput(outputId = "chg_data")
))

server <- shinyServer(function(input, output, session) {
  DF <- data.frame(A = c(1, 2), B = c(3, 4), row.names = c("C", "D"))
  
  output$two_by_two <- renderRHandsontable({
    input$reset_input # trigger rendering on reset
    rhandsontable(DF)
  })
  
  output$chg_data = renderTable({
    hot_to_r(req({input$two_by_two}))*2}, rownames = TRUE)
})

shinyApp(ui, server)

运行宁此 MWE 代码时出现的内容:

我想做的事情:

也许您正在寻找这个

library(shiny)
library(rhandsontable)

ui <- shinyUI(fluidPage(
  h4("Click ´Show´ button below to trigger modal dialogue:"),
  #tags$head(tags$style(" .modal-dialog{ width:800px}")),
  tags$head(tags$style(" .modal-body{ min-height:500px}")),
  actionButton("show","Show"),
  br(),br()
))

server <- shinyServer(function(input, output, session) {
  DF <- data.frame(A = c(1, 2), B = c(3, 4), row.names = c("C", "D"))
  
  output$two_by_two <- renderRHandsontable({
    input$reset_input # trigger rendering on reset
    rhandsontable(DF)
  })
  
  output$chg_data = renderTable({
    hot_to_r(req({input$two_by_two}))*2}, rownames = TRUE)
  
  observeEvent(input$show, {
    showModal(modalDialog(title = "my display",
                          
                            actionButton(inputId = "reset_input", label = "Reset"),
                            br(),br(),
                            rHandsontableOutput("two_by_two"),
                            br(),
                            tableOutput(outputId = "chg_data"),
                          
                          easyClose = TRUE, footer = NULL, class = 'success'
    ))
  })
  
})

shinyApp(ui, server)