简体   繁体   English

R Shiny:eventReactive输出的初始呈现

[英]R Shiny: initial rendering of eventReactive output

What I'm trying to achieve is to have an initial table to be rendered right as the app is executed. 我想要达到的目的是在执行应用程序时立即呈现一个初始表。 But then, update the table only on executing action. 但是,仅在执行操作时更新表。

Here's the example: 例子如下:

library(shiny)
library(data.table)

dt <- data.table(x = c("a", "b"), y = c(0,0))

ui <- fluidPage(

  sidebarLayout(

    sidebarPanel(
      selectInput(inputId = "inSelect", 
                  label = "Select:", 
                  choices = dt[,unique(x)]), 

      actionButton(inputId = "trigger",
                   label = "Trigger", 
                   icon = icon("refresh"))
    ),

    mainPanel(
      tableOutput("outTable")
    )

  )

)



server <- function(input, output){

  re <- eventReactive(input$trigger, {
    dt[x == input$inSelect, y := y + 1]
  })

  output$outTable <- renderTable({
    re()
  })

}

shinyApp(ui, server)

So the issue is that under renderTable() I can put either dt to show initial table or re() to show each update after first press of the "Trigger" button. 因此,问题在于,在renderTable()我可以在第一次按下“触发器”按钮之后将dt放到初始表中,或者在re()放下每次更新。

Do

  re <- eventReactive(input$trigger, {
    dt[x == input$inSelect, y := y + 1]
  }, ignoreNULL = FALSE)

From ?eventReactive : 来自?eventReactive

Both observeEvent and eventReactive take an ignoreNULL parameter that affects behavior when the eventExpr evaluates to NULL (or in the special case of an actionButton, 0). 当eventExpr评估为NULL(或在actionButton的特殊情况下为0)时,observeEvent和eventReactive都采用ignoreNULL参数,该参数会影响行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM