Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
greg-minshall opened this issue May 16, 2020 · 7 comments · Fixed by #141
Closed

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

greg-minshall opened this issue May 16, 2020 · 7 comments · Fixed by #141
Assignees

Comments

@greg-minshall
Copy link

greg-minshall commented May 16, 2020

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! :)

@OneTrueCzar
Copy link

OneTrueCzar commented Jan 10, 2023

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)```

@bomeara
Copy link

bomeara commented May 13, 2023

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.

@gadenbuie
Copy link
Member

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")

@gadenbuie gadenbuie self-assigned this May 15, 2023
@OneTrueCzar
Copy link

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

@bomeara
Copy link

bomeara commented May 19, 2023

Same for me. THANK YOU!

@Arnavkar
Copy link

Arnavkar commented Sep 9, 2024

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

@gadenbuie
Copy link
Member

@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()).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants