DT icon indicating copy to clipboard operation
DT copied to clipboard

[FR] SearchBuilder works with Server-Side processing mode

Open AhmedKhaled945 opened this issue 3 years ago • 4 comments

Hello, so a really helpful extension added to this repo was SearchBuilder, and while using it, once i go to server processing mode (server = true), it doesn't work, and this is a must on my side because i am dealing with fairly large data,

So is there any solution for this?, whether to optimize the data flow on client side (server = false) or to make the extension work on server side processing?

Regards,


By filing an issue to this repo, I promise that

  • [ ] I have fully read the issue guide at https://yihui.name/issue/.
  • [ ] I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('DT'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/DT').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • [ ] I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

AhmedKhaled945 avatar Feb 09 '22 15:02 AhmedKhaled945

Unfortunately, you can't use the server-processing mode with SearchBuilder at the present.

The good news is, it's possible now. We will consider to implement this feature.

**Note for myself: ** we need to translate the following "searchBuilder" JSON message to R expression.

{"method":"update","data":{"tbl_state":{"time":1644504799036,"start":0,"length":10,"order":[],"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true},"columns":[{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}},{"visible":true,"search":{"search":"","smart":true,"regex":false,"caseInsensitive":true}}],"childRows":[],"searchBuilder":{"criteria":[{"condition":"=","data":"Sepal.Width","type":"num","value":["3"]},{"condition":">","data":"Petal.Length","type":"num","value":["5"]}],"logic":"AND"},"page":0}}}	1644504799.0447066

quick example

library(shiny)
tbl = data.frame(
  COL_INT = 1:20,
  COL_DBL = as.double(101:120),
  COL_FAC = as.factor(LETTERS[1:20]),
  COL_STR = letters[1:20],
  COL_DATE = Sys.Date() + 1:20,
  COL_TIME = Sys.time() + (1:20) * 3600 * 24
)
ui = fluidPage(
  DT::DTOutput("tbl")
)
server = function(input, output, session) {
  output$tbl = DT::renderDT({
    DT::datatable(
      tbl, options = list(dom = "Qlfrtip"),
      extensions = c("SearchBuilder", "DateTime")
    )
  })
}
runApp(list(ui=ui, server=server))

shrektan avatar Feb 10 '22 14:02 shrektan

That would be really helpful, Thanks.

AhmedKhaled945 avatar Feb 10 '22 16:02 AhmedKhaled945

The full condition possibilities

https://github.com/DataTables/SearchBuilder/blob/2a3ceb327baf397ff5522088facd1f9db8c8d2f9/src/criteria.ts#L867-L2003

But there's one issue need to be resolved first:

The conditions "=", ">=" and "<=" are encoded without properly "quote", thus on the Shiny side (I mean in the Ajax callback), the query content would be "", ">" and "<" only.

shiny::parseQueryString("searchBuilder[criteria][0][condition]=<=&searchBuilder[criteria][0][data]=COL_INT")
#> $`searchBuilder[criteria][0][condition]`
#> [1] "<"
#> 
#> $`searchBuilder[criteria][0][data]`
#> [1] "COL_INT"

Opening the developper tools, I find that the browser indicates the original data contains the "=" sign.

image

The "=" sign in the query string should be encoded as "%3D" but I'm not sure it's an issue of datatable itself or it's a DT issue.

@yihui any thoughts?

shrektan avatar Feb 12 '22 09:02 shrektan

@yihui , my investigation finds it could be a bug of DT, as the browser sends out correct encoded strings (in Chrome I can see the raw POST content).

https://github.com/rstudio/DT/blob/cccd35e55228b1f702d7f472c1fe5516fd5b8ba0/R/shiny.R#L559-L562

Removing the URLdecode() will get the correct result, as shiny::parseQueryString() would perform URLdecode() internally. I'm going to file a fix later.

shrektan avatar Feb 12 '22 14:02 shrektan

Hello, I see that this ticket is still open and it seems that the SearchBuilder DT extension does not work when server=TRUE (with latest R, shiny and DT). Are there plans to implement this soon? Thank you.

isthisthat avatar Apr 26 '23 08:04 isthisthat

@isthisthat For now, due to limited resources, I'd say it's unlikely for us to implement it unless someone else implements it and sends a PR. Sorry!

yihui avatar Apr 26 '23 13:04 yihui

Thanks for confirming!

isthisthat avatar Apr 26 '23 15:04 isthisthat

@AhmedKhaled945 @isthisthat Great news: @mikmart has generously helped implement this feature! Now you can install the development version via

remotes::install_github('rstudio/DT')

and try it out.

Thanks everyone!

yihui avatar Jan 20 '24 17:01 yihui

It works!! Amazing work @mikmart !! Thank you

isthisthat avatar Jan 22 '24 15:01 isthisthat