【问题标题】:Conditional renderDataTable条件渲染数据表
【发布时间】:2020-02-27 11:51:12
【问题描述】:

在应用程序中有两个动作按钮,“tasto.a”和“tasto.b”,如果我按下“key.a”按钮 data.frame “a”被分配给 tab.SDO(),如果我按下“key.a”按钮 data.frame“a”被分配给 tab.SDO(),以便在 ui 中呈现所选的 data.frame。问题是即使我按下“key.b”键,也只会进行列表中的第二个赋值(tab.SDO

require(shiny)

a <- data.frame(a.x = c(1,3,4,5,1,2), a.y = c("A", "A", "B", "B", "C", "C"))
b <- data.frame(b.x = c(21,33,44,52,13,27), b.y = c("D", "D", "E", "E", "F", "F"))


#### UI ####
ui <- navbarPage(title = "FLUSSI SANITARI",
                 theme = shinytheme("cerulean"),     
                 #### Schede di dimissione ospedaliera ####
                 tabPanel(title = "prova", 
                          sidebarLayout(
                            sidebarPanel(
                              actionButton("tasto.a", "a"),
                              actionButton("tasto.b", "b")
                            ),
                            mainPanel(
                              div(DT::dataTableOutput("tabella.SDO"), style = "font-size:80%")
                            )
                          )

                 )
)

#### SERVER ####
server <- function(input, output, session) {

  tab.SDO <- eventReactive(input$tasto.a, {a})
  tab.SDO <- eventReactive(input$tasto.b, {b})


  output$tabella.SDO <- DT::renderDataTable({tab.SDO()}, rownames = FALSE,
                                            options = list(pageLength = 25)
  )


}

# Run the application 
shinyApp(ui = ui, server = server)

【问题讨论】:

    标签: r shinyapps


    【解决方案1】:

    您可以使用反应值和一些observeEvent

    server <- function(input, output, session) {
    
      tab.SDO <- reactiveVal(a)
      observeEvent(input$tasto.a, {
        tab.SDO(a)
      })
      observeEvent(input$tasto.b, {
        tab.SDO(b)
      })
    
      output$tabella.SDO <- DT::renderDataTable({tab.SDO()}, rownames = FALSE,
                                                options = list(pageLength = 25)
      )
    
    }
    

    【讨论】:

      猜你喜欢
      • 2020-06-30
      • 2021-02-05
      • 1970-01-01
      • 2021-11-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-04
      • 2019-07-27
      • 1970-01-01
      相关资源
      最近更新 更多