dynamic filtering by "contain" using filter-dplyr & grepl

1,342 views
Skip to first unread message

Hassan Al Shekha

unread,
Jan 14, 2016, 2:06:33 AM1/14/16
to Shiny - Web Framework for R
Hello All,


I'm learning Shiny and wondering how to make a dynamic filtering for my df (named as HR_DeltaCalc)  using the  filter (dplyr) & grepl to make (filter by contain) dynamically based on a a drop list (selectInput) that the user will pick one item (here named KPI).
Shiny works fine and provide a drop list that the user pick on KPI (see examples below from these KPIs...KPIs here are a column in my df) and I want to filter the rows in my df by this selected text.
drop list working fine and the issue that filtering is not yet.... 

I tried to use just the filter...it didn't work.
Also tried by adding grepl so it can be like contains, but it didn't work yet.
Tried to use grepl(str_c("'",as.character(input$variablex),"'"), kpi), but that also didn't work yet.

Thanks in advance for any advice on this.

 




  output$Delta_Top_HR <- renderDataTable({
            HR_DeltaCalc %>% 
              filter(grepl(as.character(input$variablex), kpi)) %>%
                arrange(desc(deltaDiff)) %>% 
                  slice(1:input$nlabels) %>% 
                    select(network.element)

  })

"kpi" is a column in my data frame type factor (currently) and it contains strings like below  

==============================

_Data_acc_ACC02_wo_reptn(Data_acc_ACC02_wo_reptn)(%)
_VoLTE_Setup_Sucess_Rate(VoLTE_SR_RRC_eRAB)(%)
VS_RRC_cnx_WithoutRepetition_fail(L12315_20_CI)(No unit)
VS_RRC_cnx_WithoutRepetition_succ_rate(L12315_11_CI)(%)
VS_RRC_cnx_WithoutRepetition_req(L12315_00_SI)(No unit)
_S1_sig_estab_succ_rate_ATT(S1_sig_estab_SR_ATT)(%)
_DRB_ERAB_Setup_SR_ATT(DRB_ERAB_Setup_SR_ATT)(%)
_DRB_ERAB_Setup_Success(DRB_ERAB_Setup_Succeses)(No Unit)
_DRB_ERAB_Setup_Failures(DRB_ERAB_Setup_Failures)(No Unit)
_DRB_ERAB_Setup_attempts(DRB_ERAB_Setup_attempts)(No Unit)




1.png

Hassan Al Shekha

unread,
Jan 14, 2016, 2:11:18 AM1/14/16
to Shiny - Web Framework for R
+Adding one more snapshot for the drop list & table. 
1.png

Hassan Al Shekha

unread,
Jan 14, 2016, 3:50:00 PM1/14/16
to Shiny - Web Framework for R
Appreciate your advice in advance.


On Thursday, January 14, 2016 at 1:06:33 AM UTC-6, Hassan Al Shekha wrote:

Joe Cheng

unread,
Jan 14, 2016, 9:00:25 PM1/14/16
to Hassan Al Shekha, Shiny - Web Framework for R
grepl will treat your search criteria as a regular expression--is that what you want? If you are looking for a straight up string match, then just use filter(input$variablex == kpi); if you want a substring match then use filter(grepl(input$variablex), kpi, fixed = TRUE)).

--
You received this message because you are subscribed to the Google Groups "Shiny - Web Framework for R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to shiny-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/shiny-discuss/2aa95d66-0914-4f77-9e0c-2d74c6a2657f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hassan Al Shekha

unread,
Jan 14, 2016, 10:21:09 PM1/14/16
to Joe Cheng, Shiny - Web Framework for R
Thanks a lot Joe,


input$variablex == kpi did the job.


Really Appreciated.
--
Best regards,

Hassan Al Shekha.
Reply all
Reply to author
Forward
0 new messages