gpt4 book ai didi

将 dateRangeInput 恢复为空

转载 作者:行者123 更新时间:2023-12-04 10:18:56 24 4
gpt4 key购买 nike

我可以开始dateRangeInput与空 startend在 Shiny 。

dateRangeInput("date", "Date input", start = "", end = "")

在此日期范围内进行选择后,当我尝试

updateDateRangeInput(session, "date", start = "", end = "")

它不起作用。它适用于其他类型的输入(见下文)。

这是一个reprex,当我点击go时它会输入日期,当我点击go2时它什么都不做。

library(shiny)
shinyApp(
ui = fluidPage(
h4("Date:"),
# Starting with an empty date
dateRangeInput("date", "Date input", start = "", end = ""),
actionButton("go","go"),
actionButton("go2","go2"),
# And an empty button
textInput("text", "text"),
actionButton("go3","go3")
),
server = function(input, output, session){
observeEvent( input$go , {
# Will change the date accordingly
updateDateRangeInput(
session,
"date",
start = Sys.Date()-10,
end = Sys.Date()-5
)
})
observeEvent( input$go2 , {
# Does nothing
updateDateRangeInput(
session,
"date",
start = "",
end = ""
)
})
observeEvent( input$go3 , {
# Empties the text input
updateTextInput(
session,
"text",
value = ""
)
})
}
)

最佳答案

似乎需要日期格式。您可以使用 NA而不是 "" .

library(shiny)
shinyApp(
ui = fluidPage(
h4("Date:"),
dateRangeInput("date", label = h5("Date input"), start = "", end = ""),
actionButton("go","go"),
actionButton("go2","go2")
),
server = function(input, output, session){
observeEvent( input$go , {
cat("go1\n")
updateDateRangeInput(session, "date", start = Sys.Date()-10, end = Sys.Date()-5)
})
observeEvent( input$go2 , {
cat("go2\n")
updateDateRangeInput(session, "date", start = NA, end = NA)
})
}
)

关于将 dateRangeInput 恢复为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54709263/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com