![](/img/trans.png)
[英]Shiny R observeEvent with Multiple Conditions from selectInput
[英]multiple conditions observeEvent - R Shiny
我正在尝试制作一个 Shiny 应用程序,其中包含一个显示海洋动物标签的交互式 map。 目前,我有三个可能的输入:(1) 标签编号,(2) 动物的大小和 (3) 我想要显示的月份。 对于它的大小,当我更新标签号输入时它很容易工作,但我坚持了几个月......我已经尝试过:
observeEvent({input$selected_tag
input$selected_month},{...
并通过将输入包含在反应式表达式中但会发生错误:
Avis : Error in sum: 'type' (list) de l'argument incorrect
请问你有什么想法吗? 还是我的输入定义不明确(参见错误)? 这是一个代表和我的数据样本https://github.com/rc.net/ABFT_migration/blob/main/test_file.csv (符合 #### 当你点击标签时会发生什么?### #):
library(shiny)
library(leaflet)
library(lubridate)
#### Data loading ####
### Tags table
tag_data <- read.csv("test_file.csv", header = TRUE, sep=",",dec=".")
tag_data$tag <- as.factor(tag_data$tag)
id_tag <- levels(tag_data$tag)
tag_data$date = ymd(tag_data$date)
## Definition of the applicable filters
filtering_option <- c("Size", "Months")
## Definition of the seasons
months_tag <- c("January", "February", "March", "April",
"May", "June", "July", "August", "September",
"October", "November", "December")
################################################################################
#### Shiny app UI ####
ui <- fluidPage(
tabsetPanel(
column(2, selectizeInput("selected_tag", "Which tags do you want to see ?",
choices = id_tag, multiple = TRUE),
hr(), ## Filters
p(strong("Which filter do you want to use ?")),
checkboxInput("filter_size", "Size"),
conditionalPanel(condition = "input.filter_size == 1",
sliderInput("slider_size", "Choose a size range (in cm)",
value = c(min(unique(tag_data$size_at_tagging)),
max(unique(tag_data$size_at_tagging))),
min = min(unique(tag_data$size_at_tagging)),
max = max(unique(tag_data$size_at_tagging)))
),
checkboxInput("filter_month", "Months"),
conditionalPanel(condition = "input.filter_month == 1",
selectizeInput("selected_month",
"Which months do you want to see ?",
choices = months_tag,
selected = months_tag[1],
multiple = TRUE)),
actionButton("reset_button", "Reset"),
textOutput("test_debbuging")),
column(10, leafletOutput("map_tag", height = "850px"))
))
################################################################################
#### Shiny app server ####
server <- function(input, output, session) {
observeEvent(input$selected_month, {cat(input$selected_month, "\n")})
observeEvent(input$selected_tag, {cat(input$selected_tag)})
}
shinyApp(ui, server)
'''
您可以定义所需输入参数的列表:
toListen <- reactive({
list(input$selected_tag, input$selected_month)
})
然后将您的反应列表与您的observeEvent
结合使用:
observeEvent(toListen(),{...})
所以经过几次尝试,我终于弄明白了。 该错误确实在 leaflet 中。问题在于 addAwesomeMarkers 的 label 参数。 通过“弹出”更改“标签”,应该没问题! (因为我不得不减少我的代表,错误不再出现在我最初的帖子中)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.