【问题标题】:In R shiny how to move table and related inputs, generated using rhandsontable, into a modal dialogue box?在 R Shiny 中,如何将使用 rhandsontable 生成的表和相关输入移动到模态对话框中?
【发布时间】:2021-10-01 02:33:31
【问题描述】:

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

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

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

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 代码时会出现什么:

我想做的事:

【问题讨论】:

    标签: r shiny modal-dialog rhandsontable


    【解决方案1】:

    也许你正在寻找这个

    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)
    

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-30
      • 2017-05-31
      • 2018-05-18
      • 2018-03-14
      相关资源
      最近更新 更多