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

updatePrettyRadioButton has issues when updating the label #162

Closed
melvidoni opened this issue Mar 15, 2019 · 2 comments
Closed

updatePrettyRadioButton has issues when updating the label #162

melvidoni opened this issue Mar 15, 2019 · 2 comments

Comments

@melvidoni
Copy link

I have this simple function to add a red star in a mandatory option:

labelMandatory <- function(label) {
  tagList(label, span(style="color:red", " *"))
}

If I use it on a normal button, slider, or whatever element, it works fine:

 box(prettyRadioButtons("gender", label = labelMandatory("Indicate your Gender"),
        choices = c("Female", "Male", "Other"), icon = icon("check"),
        bigger = TRUE, status = "info", animation = "jelly"), status = "primary"),

But, if I use it with updatePrettyRadioButtons, then the output is rendered as Question here... [object Object]. Here is the update code:

updatePrettyRadioButtons(session, inputId = "ycu2c", choices = choicesCU2C, 
                   label = labelMandatory(questionCU2C),
                    prettyOptions = list(bigger = TRUE, status = "info", shape = "round",
                                      animation = "jelly", icon = icon("check")))
@pvictor
Copy link
Member

pvictor commented Mar 20, 2019

Hello,
Unfortunately you can only update label with plain text, that's how it's designed in radioButtons bindings from Shiny (which prettryRadio use).
You can achieve what you want with a renderUI like this :

library(shiny)
library(shinyWidgets)

labelMandatory <- function(label) {
  tagList(label, span(style="color:red", " *"))
}

ui <- fluidPage(
  prettyRadioButtons(
    inputId = "gender", 
    label = labelMandatory(uiOutput(outputId = "label_gender", inline = TRUE)),
    choices = c("Female", "Male", "Other"),
    icon = icon("check"),
    bigger = TRUE,
    status = "info", 
    animation = "jelly"
  ),
  textInput(inputId = "label", label = "New label:"),
  actionButton(inputId = "update", label = "Update")
)

server <- function(input, output, session) {
  
  label_gender_rv <- reactiveValues(text = "Indicate your Gender")
  
  observeEvent(input$update, {
    label_gender_rv$text <- input$label
  })
  
  output$label_gender <- renderUI({
    label_gender_rv$text
  })
  
}

shinyApp(ui, server)

Victor

@melvidoni
Copy link
Author

That is a good workaround. Thank you!

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