首页 > 解决方案 > 这两个反应式数据帧是动态的。但是输出正在合并

问题描述

输出(2 个数据帧)正在合并。由于数据框是动态的,我希望输出一个接一个地显示。(航班和战术是标签面板)

ui <- fluidPage( 
  fluidRow(
    column(3, wellPanel(
      textInput("account","Enter the Account Name",""),
      tags$hr(),
      actionButton("goButton", "Go")
    )),
    mainPanel(
        tabsetPanel(
          tabPanel("Flight",            
                   textInput("flightname","Enter the flight Name","")
                   tags$hr(),
                   actionButton("go", "Go")),
          tabPanel("Tactic", 
                   textInput("tacticname","Enter the tactic Name",""),
                   tags$hr(),
                   actionButton("go1", "Go"))
        ),
      column(3,dataTableOutput('mytable1')),
      conditionalPanel(
        condition = "input.go1 != 0",
        column(3,dataTableOutput('mytable2')))
     )
  ))
server <- function(input, output) {
rv <- reactiveValues(fli = data.frame("FlightName" = character(), "AddedValue" = character()))

  observeEvent(input$go, {
    # Bind new row to rv$fli
    rv$fli <- rbind(
      rv$fli, 
        data.frame("Account"=input$account"FlightName"=input$flightname)
    )
  })

  rv1 <- reactive({rv$fli})

  output$mytable1  <- DT::renderDataTable(
    DT::datatable(
      rv1(),
      extensions = 'Buttons',
      options = list(
        paging = TRUE,
        dom = 'tB',
        buttons = c('copy', 'csv', 'excel','pdf')
      ),
      class = "display"
    ))

  rv <- reactiveValues(tact = data.frame("TacticName" = character()))

  observeEvent(input$go1, {
    rv$tact <- rbind(
      rv$tact, 
      data.frame("Account"=input$account,"TacticName"=input$tacticname))
  })

  rvt <- reactive({rv$tact})
}}

使用类似的 DT::renderDataTable 来显示 rvt()。在 ui 部分,我使用的是 column(3,dataTableOutput('mytable1')) 和 column(3,dataTableOutput('mytable2'))。

标签: rdynamicshinyoutput

解决方案


推荐阅读