我正在开发一个模块化的闪亮应用程序,但遇到了一些问题。在这个模块中,我试图给予用户计算两个日期之间变化的能力,并将它们显示在几个图表和reactables中。
代码如下:
calcChangesModuleUI <- function(id) {
ns <- NS(id)
tagList(
sidebarLayout(
sidebarPanel(
h4("Choose dates here:"),
selectInput(ns("date_start"), "Select start", choices = NULL),
selectInput(ns("date_end"), "Select end", choices = NULL),
actionButton(ns("submit"), "Submit")
),
mainPanel(
conditionalPanel(
condition = "input.submit == 0",
h4("Choose and start and end, then hit 'Submit'")
),
conditionalPanel(
condition = "input.submit > 0",
hr(),
h4("Factors"),
plotlyOutput(ns("chart1")),
hr(),
h3("Drivers"),
reactableOutput(ns("summary_table")),
)
)
)
)
}
calcChangesModule <- function(input, output, session) {
data <- readRDS("C:/A_place/lots_of_data.RDS")
selectable_dates <- reactive({
dates_from_data <- unique(data[["Pretty Consistent Dataset"]]$Date)
dates_from_data
})
observe({
updateSelectInput(session, "date_start", choices = selectable_dates())
updateSelectInput(session, "date_end", choices = selectable_dates())
})
observeEvent(input$submit, {
date1 <- input$date_start
date2 <- input$date_end
req(date1, date2)
print(date1)
print(date2)
if(!is.null(date1) && !is.null(date2)){
print("Inside the conditional block")
# loads and loads of calculations
# followed quickly by reactable and plotlys
})
}
虽然conditionalPanel()的工作符合预期,但BullveEvent()似乎根本没有触发(我也尝试过eventReactive)-它既不打印date 1或date 2,也不打印“条件块内部”;有谁知道为什么会这样吗任何帮助都非常感谢。
编辑:添加了'actionButton(ns(“submit”),“Submit”',遗憾的是条件不再起作用。
1条答案
按热度按时间dvtswwa31#
通过添加以下内容解决了这一问题:actionButton(ns(“提交”),“提交”)
并且:ns = ns in the conditionalPanel()s