shiny - Shiny: Display textOutput() if input is different from the default value
问题描述
I have a Shiny App with multiple inputs of different kinds (checkboxGroupInput
, sliderInput
, dateRangeInput
...) with default selected values.
I am trying to display a text message at the top of my dashboardBody
if the input values are different from the default ones.
ui <- dashboardPage(
#one of the inputs
dateRangeInput(
"date_reception",
"Sélectionnez une plage de dates",
start = min(dataset_all$date_reception),
end = max(dataset_all$date_reception),
),
#the output to show if input is different from default
textOutput("warning_filters")
----------
)
server <- function(input, output) {
observeEvent(input$date_reception,
{
if ((input$date_reception[1] != min(dataset_all$date_reception)) |
(input$date_reception[2] != max(dataset_all$date_reception))) {
output$warning_filters <-
renderText({
"Warning: filters apply"
})
} else{
NULL
}
})
}
My issue is that the message is correctly displayed when I change one of the dates but does not disappear when I select again the default value (here, min(dataset_all$date_reception)
or max(dataset_all$date_reception)
).
I have tried playing with ignoreNULL
and ignoreInit
but nothing changed.
Thank you for your help!
解决方案
warning_filters
当条件为假时,您需要重新分配。现在,warning_filters
设置为警告文本,即使您NULL
在条件不成立时返回函数,您实际上也不会更改warning_filters
. 下面的代码应该可以工作。
observeEvent(input$date_reception,
{
if ((input$date_reception[1] != min(dataset_all$date_reception)) |
(input$date_reception[2] != max(dataset_all$date_reception))) {
output$warning_filters <-
renderText({
"Warning: filters apply"
})
} else{
output$warning_filters <- NULL
}
})
}
推荐阅读
- haskell - HASKELL:在数据库查询中使用 Maybe(或其他...)处理 NULL 值
- angular - 我使用 Angular 4 webapi2 遇到跨源错误
- vue.js - Vue.js 更新数组无法使用 this.$set
- postgresql - 如果大于最大值,则从上一行值中减去值
- r - 是否可以仅根据其位置指定的参数类来调度 S3 方法?
- javascript - 在加载数据期间在表格上显示加载/进度/微调器
- apache-kafka - Kafka 主题具有 leader=-1 的分区(Kafka Leader Election),而节点已启动并正在运行
- css - Chrome 和 Firefox 浏览器扩展 内容脚本中的 CSS 图像 url
- angular - 创建动态对象时出现问题
- python - Python - 如何从文本中打印出一行