Я столкнулся с проблемой, при которой я хотел бы отфильтровать таблицу DT, используя значения, введенные из SelectInput. Это работает хорошо, но таблица появится только в том случае, если я завершил все значения, которые я фильтрую.
Я бы хотел, чтобы таблица отображалась, если значения в SelectInput равны NULL, однако это не работает . Мне интересно, есть ли у кого-нибудь совет, как показать таблицу, когда SelectInput в NULL для всех категорий или только для некоторых. Другими словами, я хотел бы отключить фильтрацию SelectInput, если ничего не выбрано.
Ниже приведен фрагмент кода, имеющий отношение к этой проблеме.
box(selectInput("category", "Select Category", sources_cat, selected = NULL, multiple = TRUE),
selectInput("age", "Select Age Group", sources_age, selected = NULL, multiple = TRUE),
selectInput("country", "Select Country", sources_count, selected = NULL, multiple = TRUE)),
box(HTML("<br/> <h5><b>Topic Definitions</b></h5> <br/>")),
),
box(width = NULL, dataTableOutput('table'))
),
server <- function(input, output){
output$table <- DT::renderDataTable({
cat <- input$category
country_input <- input$country
age_select <- input$age
input1 <- input1
input2 <- input2
fsources <- sources %>%
filter(grepl(country_input[1], country) | grepl(country_input[2], country) | grepl(country_input[3], country) |
grepl(country_input[4], country))
fsources <- fsources %>%
filter(grepl(age_select[1], age) | grepl(age_select[2], age) | grepl(age_select[3], age))
fsources <- fsources %>%
filter(grepl(cat[1], topics) | grepl(cat[2], topics) | grepl(cat[3], topics) |
grepl(cat[4], topics))
#this output table only appears if there is a country and a topic selected. If not, it has an error. One must chose a country or a topic
datatable(fsources, extensions = 'Buttons', options = list(
dom = 'Bfrtip',
buttons = c('copy', 'csv', 'excel', 'pdf', 'print')
))
})
Сообщение об ошибке, когда SelectInput == NULL
![The error message when SelectInput == NULL](https://i.stack.imgur.com/iKEWj.png)