rstudio / crosstalk

Inter-htmlwidget communication for R (with and without Shiny)

Home Page:http://rstudio.github.io/crosstalk

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

filter_select() group argument: '&' where '&' is wanted

greg-minshall opened this issue · comments

hi. i wonder if the vector passed as the group argument to filter_select() is passed twice through htmlEscape()? in the following example, if you click in the search field, you'll see two possibilities, one that did not, and one that did, have an ampersand. the one with the ampersand shows as "&".

require(tibble)
require(plotly)
require(DT)
require(crosstalk)

repro <- function() {
  collie <- c("group and no problem", "group & maybe a problem")
  esel <- tibble(x=1:2, y=2*(1:2), label=collie);
  em1 <- crosstalk::SharedData$new(esel, group="shareddatagroup")
  fselect <- filter_select("filterselectid", "label", em1, collie)
  ex1 <- em1 %>% plot_ly(x=~x, y=~y, showlegend=FALSE)
  dt1 <- DT::datatable(em1, elementId="dtelementid",
                       options=list(searching=TRUE, dom=sub("f", "", "lfrtip")))
  crosstalk::bscols(list(fselect, ex1, dt1))
}
repro()

cheers!

(amusingly, above, after "shows as", i had to type " & a m p ; a m p ; " (without the spaces) rather than just the first five characters. escape sequences are always problematic! :)

Hello, I just wanted to bump this as I have had the same issue in my shiny app and not found a solution (or even if a solution is possible based on how filter_select() works. I have an MRE down below as well:

library(tidyverse)
library(crosstalk)
library(shiny)

df <- tibble(points = c(10, 12, 14), 
             stadium = c("M&T Bank Stadium", "Wembley Stadium", "FirstBank Stadium"))

df_crosstalk <- SharedData$new(df)

df_react <- 
  reactable(df_crosstalk)

ui <- fluidPage(
  titlePanel("Test Ampersand"),
  fluidRow(
    column(
      4,
      filter_select(
        id = "stadium",
        label = "Stadium",
        sharedData = df_crosstalk,
        group = ~`stadium`)
      ),
    column(
      8,
      df_react
    )
  )
)

server <- function(input, output, session) {
  output$table <- renderReactable({
    df_react
  })
}

shinyApp(ui, server)```

I'm having the same issue. Note that for @OneTrueCzar's MRE to run, you also have to library(reactable). I could change my source data from ampersand to and, but for my specific problem it would be odd: "Texas A and M" is far better known as "Texas A&M" for example.

Hi all! Thank you @greg-minshall for posting the original issue, @OneTrueCzar for the reprex, and @bomeara for the recent bump. @greg-minshall's intuition that two rounds of html escaping were occurring turns out to be spot on; we escaped the HTML on the R side and the selectize JavaScript library performs a second round of escaping when creating the select input.

I have a proposed fix in #141 if you would like to try it out or need a quick fix. You can use the following to install crosstalk directly from that branch (until it's merged).

remotes::install_github("rstudio/crosstalk#141")

Hi @gadenbuie , thanks for the fix! I just tested it on my end and it works perfectly, thank you so much!

Same for me. THANK YOU!

Hi @gadenbuie! Still coming across the same issue on my end and the fix proposed does not work because the branch is no longer there I think

@Arnavkar the fix from the branch was merged and released in crosstalk 1.2.1. If you're using that version of crosstalk, please open a new issue with a reproducible example and your session info (devtools::session_info()).