【问题标题】:R Shiny: initial rendering of eventReactive outputR Shiny:eventReactive 输出的初始渲染
【发布时间】:2019-09-09 19:47:11
【问题描述】:

我想要实现的是在执行应用程序时正确呈现初始表。但是,仅在执行操作时更新表。

示例如下:

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)

所以问题是在renderTable() 下我可以在dt 下显示初始表格或re() 在第一次按下“触发器”按钮后显示每个更新。

【问题讨论】:

  • ignoreNULL = FALSE eventReactive() 的参数

标签: r shiny


【解决方案1】:

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

来自?eventReactive

observeEvent 和 eventReactive 都带有一个 ignoreNULL 参数 影响 eventExpr 评估为 NULL 时的行为(或在 actionButton 的特殊情况,0)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-11
    • 2016-11-15
    • 1970-01-01
    相关资源
    最近更新 更多