我有一个闪亮的应用程序,用户可以选择两个日期范围和一个提交按钮 第一个日期范围用于分析期间,而第二个日期范围是应该在第一个日期范围内的范围。
我使用dateRangeInput,我想设置第二个dateRangeInput的最小和最大日期等于第一个dateRangeInput中用户选择的时间段。我现在的问题是我现在设置它的方式,第二个dateRangeInput不会刷新,直到用户点击提交,而我希望它在第一个dateRangeInput时立即刷新变化。
我如何实现这一目标?
到目前为止,我的代码看起来像这样:
#ui.R
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
dateRangeInput('inputDate', 'Select date range for analysis period', start = '2015-07-01', end = '2015-07-03', min = min_date, max = max_date),
#the output below is refreshing only when the user hits submit, but I would like it to refresh as soon as the first dateRangeInput changes.
uiOutput('return_dates'),
submitButton("Submit")
),
mainPanel()
)))
#server.R
shinyServer(function(input, output, session) {
ret_min <- reactive({
input$inputDate[1]
})
ret_max <- reactive({
input$inputDate[2]
})
output$return_dates <- renderUI({
dateRangeInput('inputDate2', 'Select date range for return period', start = '2015-07-01', end = '2015-07-02', min = ret_min(), max = ret_max())
})
analysisFunction <- reactive({
#code here performs analysis based on the given date range, and should run only when the user hits submit
})
})
答案 0 :(得分:1)
我找到了一个解决方案,即使用actionButton而不是submitButton,它允许我指定哪些函数只应在命中操作按钮时才会做出反应,而其余的函数将在输入更改后立即响应。
#ui.R
shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
dateRangeInput('inputDate', 'Select date range for analysis period', start = '2015-07-01', end = '2015-07-03', min = min_date, max = max_date),
uiOutput('return_dates'),
actionButton("submitButton","Submit")
),
mainPanel()
)))
#server.R
shinyServer(function(input, output, session) {
ret_min <- reactive({
input$inputDate[1]
})
ret_max <- reactive({
input$inputDate[2]
})
output$return_dates <- renderUI({
dateRangeInput('inputDate2', 'Select date range for return period', start = '2015-07-01', end = '2015-07-02', min = ret_min(), max = ret_max())
})
analysisFunction <- reactiveEvent({input$submitButton, {
#code here will only run when user hits submit
})
})