r - updateSelectizeInput 不起作用,导致服务器行为异常
问题描述
我正在尝试使用盆地,然后更新该盆地内子盆地的可能选择。但是,我的代码不起作用。我不能使它既不使用observe
,也不使用reactive
,或者使用observeEvent
或不使用所有这些。
我ui
这边是:
selectInput(inputId = 'countyType_id',
label = '1. Select a basin',
choices = all_basins
),
selectizeInput(inputId = 'subbasins_id',
label = '2. Select subbasins',
choices = subbasins,
selected = head(subbasins, 1),
multiple = TRUE)
服务器端看起来像:
observe({
#
# from
# https://shiny.rstudio.com/reference/shiny/latest/updateSelectInput.html
#
subbasins <- sort(unique(curr_spatial$subbasin))
# Can also set the label and select items
updateSelectizeInput(session,
server = FALSE,
"subbasins_id",
label = "2. Select subbasins",
choices = subbasins,
selected = head(subbasins, 1)
)
# It seems the followin has no effect:
# and when it is outside observe, it produces errors!
curr_spatial <- curr_spatial %>%
filter(subbasin %in% input$subbasins_id) %>%
data.table()
})
有输入吗?请。我确实将数据和整个代码放在了谷歌驱动器中: https ://drive.google.com/file/d/1qaZG6-VmBhIgMsxs5dffX9PmagkMhuB8/view?usp=sharing
解决方案
第二个 selectInput 应该从服务器而不是从 UI 呈现以进行交互。
用户界面
selectInput(inputId = 'countyType_id',
label = '1. Select a basin',
choices = all_basins
),
uiOutput('subbasins_id')
服务器.R
output$subbasins_id <- renderUI({
## add some code to filter subbasin based on the selected basin, i.e. input$countyType_id
curr_spatial <- curr_spatial %>%
filter(subbasin %in% input$subbasins_id) %>%
data.table()
subbasins <- sort(unique(curr_spatial$subbasin))
selectizeInput(inputId = 'subbasins_id',
label = '2. Select subbasins',
choices = subbasins,
selected = head(subbasins, 1),
multiple = TRUE)
})
推荐阅读
- python - 在 Django 中导入 csv
- c# - 将 TotpSecurityStampBasedTokenProvider 用于 TOTP 和 Google Authenticator
- swift - 是否可以使用 Bond/ReactiveKit 绑定到枚举?迅速
- hadoop - 为 SAS 表的频繁更改元数据结构创建 Hive 模式
- forms - 在 Google 跟踪代码管理器中,触发器类型“表单提交”适用于 Google 表单提交吗?
- sql-server - 需要在 Visual Studio 数据库项目中明确指定 Microsoft.Data.Tools.Schema.Tasks.Sql 版本
- android - 滑动菜单始终全屏
- javascript - D3.js 用力沿着圆圈展开正方形
- symfony - Capistrano,部署期间网站不可用
- java - 如何使用 Spark 结构化流实现 Kafka 流的自定义反序列化器?