0

I want to create a new filtered data set based on multiple selected rows in a reactive table. I can do this if a single row is selected but don't know how to do this for multiple selections.

This is my code for the data table to select from:

output$tbl<-DT:: renderDataTable({
    DT:: datatable(df,
        filter='top,
        rownames= F,
        selection=list(mode='single', target='row'),
        options=list(lengthMenu=c(3,6,15), pageLength=6, scrollx=T))})

And this is to record relevant data selection from the table to graph

tbl2<-reactive({
    req(input$tbl_rows_selected)
        table_row_selected <-df[input$tbl_rows_selected,]
    sel<- as.character(table_row_selected$Category) 

    tbl_plot<-df %>%
        filter(Category == sel) %>%
        group_by(Category) %>%
        select(Category, a,b,c) 
    tbl_plot
})

What I want to do is change selection=list(mode='single', target='row') to selection=list(mode='multiple', target='row') in output$tbl.

How do I change the code in tbl2 to accommodate for multiple selections?

Thanks.

badatr
  • 31
  • 4

1 Answers1

0

You need to use %in% -

tbl_plot <- df %>%
        filter(Category %in% sel) %>%
        # rest of the code
Shree
  • 10,835
  • 1
  • 14
  • 36