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

Support HTML for the update methods that have a label arg #624

Open
yogat3ch opened this issue Aug 15, 2023 · 1 comment
Open

Support HTML for the update methods that have a label arg #624

yogat3ch opened this issue Aug 15, 2023 · 1 comment

Comments

@yogat3ch
Copy link

yogat3ch commented Aug 15, 2023

Hi shinyWidgets devs,
It would be awesome if the update methods allowed HTML for the label arg similar to the UI component call. This currently errors if a shiny.tag is passed to label on the update method. Wrapping the tag with htmltools::doRenderTags, the update method escapes the HTML and shows it as is (shown in this example):

library(shiny)

ui <- fluidPage(
  shinyWidgets::noUiSliderInput(
    "slider",
    label = tags$span("Some HTML"),
    min = 0,
    max = 100,
    value = 55,
    step = 1,
    inline = TRUE
  ),
  actionButton(
    "update",
    "Update the label"
  )
)

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

  observeEvent(input$update, {
    shinyWidgets::updateNoUiSliderInput(
      inputId = "slider",
      label = htmltools::doRenderTags(tags$p("Some mo HTML"))
    )
  })

}

shinyApp(ui, server)
@yogat3ch
Copy link
Author

For anyone landing here looking to do this, here's a hack with shinyjs:

library(shiny)
library(shinyjs)

ui <- fluidPage(
  shinyjs::useShinyjs(),
  shinyWidgets::noUiSliderInput(
    "slider",
    label = tags$span("Some HTML"),
    min = 0,
    max = 100,
    value = 55,
    step = 1,
    inline = TRUE
  ),
  actionButton(
    "update",
    "Update the label"
  ),
  actionButton(
        "hack",
        "shinyjs the label"
      )
)

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

  observeEvent(input$update, {
    shinyWidgets::updateNoUiSliderInput(
      inputId = "slider",
      label = htmltools::doRenderTags(tags$p("Some mo HTML"))
    )
  })
  observeEvent(input$hack, {
    shinyjs::html("slider-label", htmltools::doRenderTags(tags$h3("Hack that label")), asis = TRUE)

  })

}

shinyApp(ui, server)

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

1 participant