R Shiny-无法执行操作模块中计数器的actionButton

时间:2018-08-01 14:09:16

标签: r shiny reactive

我正在尝试构建一组按钮,这些按钮允许通过一个简单的计数器浏览矢量,然后将其用作所述矢量的索引。但是,按钮根本不起作用。在按钮的代码块中进行的一些初步print()调试显示,这些部分从未执行过。这是到目前为止我得到的可运行独立代码版本。 我将自己定位在此gist上,它实现了reactiveValues计数器的工作版本,但没有模块。

所以我的问题基本上是,为什么按钮不起作用,因为应该正确命名它们。

OverviewUI <- function(id) {
  "
  This function provides the overview ui.
  "
  ns <- NS(id)

  tagList(
    h1("Overview"),
    fluidRow(
      column(actionButton(ns("previousWeek"), label = "Previous Week"), offset = 2, width = 2),
      column(h4(textOutput(ns("currentDate"))), align = "center", width = 4),
      column(actionButton(ns("nextWeek"), label = "Next Week"), width = 2)
    )
  )
}

Overview <- function(input, output, session){
  "
  This function contains the server code for the overview page.
  "
  possibleDates <- c("2018-06-11", "2018-06-18", "2018-06-25", "2018-07-02",
                     "2018-07-09", "2018-07-16", "2018-07-23", "2018-07-30")

  selection <- reactiveValues(currentDate = length(possibleDates))

  observeEvent(input$PreviousWeek, {
    if(selection$currentDate - 1 > 0) {
      selection$currentDate <- selection$currentDate - 1
    }
  })

  observeEvent(input$NextWeek, {
    if(selection$currentDate + 1 <= length(possibleDates)) {
      selection$currentDate <- selection$currentDate + 1
    }
  })

  output$currentDate <- renderText({ 
    possibleDates[selection$currentDate] 
  })
}

ui <- OverviewUI("namespace")

server <- function(input, output) {
  callModule(Overview, "namespace")
}

shinyApp(ui = ui, server = server)

0 个答案:

没有答案