Я работаю с несколькими независимыми selectizeInputs, которые должны предлагать двунаправленную фильтрацию, но я не могу заставить их работать. Когда я пытаюсь обновить selectizeInputs в моей функции сервера, они переопределяют друг друга и дают непредсказуемые результаты. Например, я ожидаю, что когда я добавлю ввод в constituency_name selectizeInput ( input $ const_name ), const_code selectizeInput должен обновиться и включать дополнительные коды, и наоборот, независимо от того, с какого из них я начинаю, но это не так. Что я делаю не так? Кроме того, дайте мне знать, если это все еще непонятно, чтобы я мог объяснить больше. См. Прилагаемые фотографии пользовательского интерфейса
#My server side statements
server <- function(input, output, session) {
observe({
if (is.not.null(input$const_code_id)){
#Observing events for const code first
observe({
dt <- voters_data$CONSTITUENCY[voters_data$CONST_CODE %in% input$const_code_id]
updateSelectizeInput (session, "const_name_id", choices = unique(voters_data$CONSTITUENCY),selected = dt)
})
observe({
dt <- voters_data$COUNTY.NAME[voters_data$CONST_CODE %in% input$const_code_id]
updateSelectizeInput (session, "county_name_id", choices = unique(voters_data$COUNTY.NAME),selected = dt)
})
observe({
dt <- voters_data$COUNTY.NAME[voters_data$CONST_CODE %in% input$const_code_id]
updateCheckboxGroupInput (session, "county_group", choices = unique(dt),selected = dt)
})
observe({
dt <- voters_data$CONSTITUENCY[voters_data$CONST_CODE %in% input$const_code_id]
updateCheckboxGroupInput (session, "constituency_group", choices = unique(dt),selected = dt)
})
} else if (is.not.null(input$const_name_id)){
#Observing events for const name first
observe({
dt <- voters_data$CONST_CODE[voters_data$CONSTITUENCY %in% input$const_name_id]
updateSelectizeInput (session, "const_code_id", choices = unique(voters_data$CONST_CODE),selected = dt)
})
observe({
dt <- voters_data$COUNTY.NAME[voters_data$CONSTITUENCY %in% input$const_name_id]
updateSelectizeInput (session, "county_name_id", choices = unique(voters_data$COUNTY.NAME),selected = dt)
})
observe({
dt <- voters_data$COUNTY.NAME[voters_data$CONSTITUENCY %in% input$const_name_id]
updateCheckboxGroupInput (session, "county_group", choices = unique(dt),selected = dt)
})
observe({
dt <- voters_data$CONSTITUENCY[voters_data$CONSTITUENCY %in% input$const_name_id]
updateCheckboxGroupInput (session, "constituency_group", choices = unique(dt),selected = dt)
})
} else if (is.not.null(input$const_name_id)){
#Observing events for const name first
observe({
dt <- voters_data$CONST_CODE[voters_data$CONSTITUENCY %in% input$const_name_id]
updateSelectizeInput (session, "const_code_id", choices = unique(voters_data$CONST_CODE),selected = dt)
})
observe({
dt <- voters_data$COUNTY.NAME[voters_data$CONSTITUENCY %in% input$const_name_id]
updateSelectizeInput (session, "county_name_id", choices = unique(voters_data$COUNTY.NAME),selected = dt)
})
observe({
dt <- voters_data$COUNTY.NAME[voters_data$CONSTITUENCY %in% input$const_name_id]
updateCheckboxGroupInput (session, "county_group", choices = unique(dt),selected = dt)
})
observe({
dt <- voters_data$CONSTITUENCY[voters_data$CONSTITUENCY %in% input$const_name_id]
updateCheckboxGroupInput (session, "constituency_group", choices = unique(dt),selected = dt)
})
} else if (is.not.null(input$county_name_id) & is.null(input$const_code_id) &
is.null(input$const_name_id) & is.null(input$county_group) & is.null(input$constituency_group)){
#Observing events for county name ID
observe({
dt <- voters_data$CONST_CODE[voters_data$COUNTY.NAME %in% input$county_name_id]
updateSelectizeInput (session, "const_code_id", choices = unique(voters_data$CONST_CODE),selected = dt)
})
observe({
dt <- voters_data$CONSTITUENCY[voters_data$COUNTY.NAME %in% input$county_name_id]
updateSelectizeInput (session, "const_name_id", choices = unique(voters_data$CONSTITUENCY),selected = dt)
})
observe({
dt <- voters_data$COUNTY.NAME[voters_data$COUNTY.NAME %in% input$county_name_id]
updateCheckboxGroupInput (session, "county_group", choices = unique(dt),selected = dt)
})
observe({
dt <- voters_data$CONSTITUENCY[voters_data$COUNTY.NAME %in% input$county_name_id]
updateCheckboxGroupInput (session, "constituency_group", choices = unique(dt),selected = dt)
})
} else if (is.not.null(input$county_name_id) & is.not.null(input$const_code_id)){
#Observing events for county name ID
observe({
dt <- voters_data$CONST_CODE[voters_data$COUNTY.NAME %in% input$county_name_id & voters_data$CONST_CODE %in% input$const_code_id]
updateSelectizeInput (session, "const_code_id", choices = unique(voters_data$CONST_CODE),selected = dt)
})
observe({
dt <- voters_data$CONSTITUENCY[voters_data$COUNTY.NAME %in% input$county_name_id & voters_data$CONST_CODE %in% input$const_code_id]
updateSelectizeInput (session, "const_name_id", choices = unique(voters_data$CONSTITUENCY),selected = dt)
})
observe({
dt <- voters_data$COUNTY.NAME[voters_data$COUNTY.NAME %in% input$county_name_id & voters_data$CONST_CODE %in% input$const_code_id]
updateCheckboxGroupInput (session, "county_group", choices = unique(dt),selected = dt)
})
observe({
dt <- voters_data$CONSTITUENCY[voters_data$COUNTY.NAME %in% input$county_name_id & voters_data$CONST_CODE %in% input$const_code_id]
updateCheckboxGroupInput (session, "constituency_group", choices = unique(dt),selected = dt)
})
} else if (is.not.null(input$county_group)){
#Observing events for county group
observe({
dt <- voters_data$CONST_CODE[voters_data$COUNTY.NAME %in% input$county_group]
updateSelectizeInput (session, "const_code_id", choices = unique(voters_data$CONST_CODE),selected = dt)
})
observe({
dt <- voters_data$CONSTITUENCY[voters_data$COUNTY.NAME %in% input$county_group]
updateSelectizeInput (session, "const_name_id", choices = unique(voters_data$CONSTITUENCY),selected = dt)
})
observe({
dt <- voters_data$COUNTY.NAME[voters_data$COUNTY.NAME %in% input$county_group]
updateSelectizeInput (session, "county_name", choices = unique(voters_data$COUNTY.NAME),selected = dt)
})
observe({
dt <- voters_data$CONSTITUENCY[voters_data$COUNTY.NAME %in% input$county_group]
updateCheckboxGroupInput (session, "constituency_group", choices = unique(dt),selected = dt)
})
} else if (is.not.null(input$constituency_group)){
#Observing events for constituency group
observe({
dt <- voters_data$CONST_CODE[voters_data$CONSTITUENCY %in% input$constituency_group]
updateSelectizeInput (session, "const_code_id", choices = unique(voters_data$CONST_CODE),selected = dt)
})
observe({
dt <- voters_data$CONSTITUENCY[voters_data$CONSTITUENCY %in% input$constituency_group]
updateSelectizeInput (session, "const_name_id", choices = unique(voters_data$CONSTITUENCY),selected = dt)
})
observe({
dt <- voters_data$COUNTY.NAME[voters_data$CONSTITUENCY %in% input$constituency_group]
updateSelectizeInput (session, "county_name", choices = unique(voters_data$COUNTY.NAME),selected = dt)
})
observe({
dt <- voters_data$COUNTY.NAME[voters_data$CONSTITUENCY %in% input$constituency_group]
updateCheckboxGroupInput (session, "county_group", choices = unique(dt),selected = dt)
})
}
})
#Butoon for clearing all filters
reset_filters <- observeEvent(input$reset_id, {
updateSelectizeInput (session, "const_code_id", choices = unique(voters_data$CONST_CODE),selected = NULL)
updateSelectizeInput (session, "const_name_id", choices = unique(voters_data$CONSTITUENCY), selected = NULL)
updateSelectizeInput (session, "county_name_id", choices = unique(voters_data$COUNTY.NAME), selected = NULL)
updateCheckboxGroupInput (session, "county_group", choices = unique(voters_data$COUNTY.NAME), selected = NULL)
updateCheckboxGroupInput (session, "constituency_group", choices = unique(voters_data$CONSTITUENCY), selected = NULL)
})
}