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

labelRenderer property in virtualSearchInput? #601

Closed
moturoa opened this issue May 26, 2023 · 4 comments
Closed

labelRenderer property in virtualSearchInput? #601

moturoa opened this issue May 26, 2023 · 4 comments

Comments

@moturoa
Copy link

moturoa commented May 26, 2023

In this example we see the use of the labelRenderer option. I was wondering if you know whether it can be used from virtualSelectInput, as the option should be passed through ...

Non-working example with selectizeInput for reference:

library(shiny)
chcs <- rownames(mtcars)

ui <- fluidPage(theme = bslib::bs_theme(version = 5),

  shinyWidgets::virtualSelectInput("sel1", "Select car (virtual select)",
                             choices = chcs,
                             labelRenderer = I('function(data){
                                                  return "<span style = \'font-size: 3em;\'>" + data.label + "</span>";
                                                }')
                             ),
  
  selectizeInput("sel2", "Select car (selectinput)", choices = chcs,
              options = list(
                render = I('{
                              item: function(data){
                                    return "<span style = \'color:red;\'>" + data.label + "</span>";
                              },
                              option: function(data){
                                    return "<div style = \'color: blue;\'>" + data.label + "</div>";
                              }
                           }
                           ')
              )
              )
)
server <- function(input, output, session) {}
shinyApp(ui, server)

Thank you!

@moturoa
Copy link
Author

moturoa commented May 26, 2023

I need to add that making the HTML beforehand, and using argument html = TRUE renders the labels nicely however using search = TRUE is weird because it then displays raw HTML as a search result.

library(shiny)
library(shinyWidgets)

chcs <- paste("<span style = 'color:red;' class = 'myclass';>",rownames(mtcars),"</span>")

ui <- fluidPage(
  tags$h4("HINT: type 's'"),
  virtualSelectInput("sel1", "Select car", choices = chcs, html = TRUE, search = TRUE,
                     showOptionsOnlyOnSearch = FALSE,
                     markSearchResults = TRUE
                     )  
)

server <- function(input, output, session) {
  
}

shinyApp(ui, server)

@pvictor
Copy link
Member

pvictor commented May 29, 2023

Hello,

For the moment, it is not possible to use the labelRenderer option: no javascript code passed as an argument is executed.
I see the issue but labelRenderer doesn't seems to fix it according to that issue sa-si-dev/virtual-select#249, this seems fixed with a PR but not released yet.
I suggest waiting for the next release to see if the problem has been corrected, and then we can look at labelRenderer if needed.

Victor

@pvictor
Copy link
Member

pvictor commented May 31, 2023

I have updated virtual-select-plugin to 1.0.38, the issue seems fixed, install from GitHub to try and let me know if it's good for you.

@moturoa
Copy link
Author

moturoa commented Jun 1, 2023

Yes that solved the issue, thank you!

@pvictor pvictor closed this as completed Jun 1, 2023
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

No branches or pull requests

2 participants