【问题标题】:shiny interacitvity between two output variables两个输出变量之间的闪亮交互性
【发布时间】:2017-03-12 20:52:32
【问题描述】:

我现在很挣扎,需要一些帮助。

我有两个 rhandondaables,因此有两个输出。在渲染函数中,我对数据框进行了一些更改,用户可以在 rhandsonable 中更改数据框。

第一个表:

 output$out <- renderRHandsontable({

if (is.null(input$out)) {
  hot <- rhandsontable(df())
} else {

  hot <- hot_to_r(input$out)
  hot <- rhandsontable(hot)
}


})

第二张桌子:

output$out2 <- renderRHandsontable({

if (is.null(input$out)) {
  hot <- rhandsontable(df())
} else {

  hot <- hot_to_r(input$out2)
  hot <- rhandsontable(hot)
}

})

为了更清楚一点,让我们假设第一个表 (output$out) 以绝对数字显示一个表,第二个 (output$out2) 以百分比显示。我想指出的是,如果一个人更新了一个表,那么另一个表也需要更新。即百分比数字需要以绝对数字计算并“返回”到一个大的平面数据表。

现在我如何使这两个交互,以便如果我更新表一,更改将提交到表二,反之亦然,以便始终反映“最新”更改。

感谢任何帮助

【问题讨论】:

    标签: r shiny output interactive


    【解决方案1】:

    如果您的两个表共享相同的基础数据,并且您在发生更改时更新基础数据,那么它应该可以工作。下面是一个简单的示例,其中两个表将显示相同的数据集。一个中的更新将反映在另一个中。

    library(shiny)
    
    ui <- shinyUI(fluidPage(
    
       titlePanel("Syncing two RHandontables"),
    
       sidebarLayout(
          sidebarPanel(
          ),
    
          mainPanel(
             rHandsontableOutput("out1"),
             tags$hr(),
             rHandsontableOutput("out2")
          )
       )
    ))
    
    server <- shinyServer(function(input, output) {
    
      data <- reactiveValues(data=head(iris))
    
      output$out1 <- renderRHandsontable({
        rhandsontable(data$data)
      })
    
      output$out2 <- renderRHandsontable({
        rhandsontable(data$data)
      })
    
      observeEvent(input$out1, {
        data$data <- hot_to_r(input$out1)
      })
    
      observeEvent(input$out2, {
        data$data <- hot_to_r(input$out2)
      })
    
    })
    
    shinyApp(ui = ui, server = server)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-02-26
      • 2021-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多