Home > database >  Shiny - How to replace chars in textInput to *** without using passwordInput?
Shiny - How to replace chars in textInput to *** without using passwordInput?

Time:07-02

I use textInput in my shinyapp. When the user write I want to see - "****" - like password field, but I don't want to use passwordInput, How can I do it with using only textInput ?

if (interactive()) {
  
  ui <- fluidPage(
    textInput("caption", "Caption", "Data Summary"),
    verbatimTextOutput("value")
  )
  server <- function(input, output) {
    output$value <- renderText({ input$caption })
  }
  shinyApp(ui, server)
}

CodePudding user response:

You could define a custom function:

textInputStars <- function(inputId, label, value = "", width = NULL,
                      placeholder = NULL) {
  
  value <- restoreInput(id = inputId, default = value)
  
  div(class = "form-group shiny-input-container",
      style = css(width = validateCssUnit(width)),
      shinyInputLabel(inputId, label),
      tags$input(id = inputId, type="password", , value=value,
                 placeholder = placeholder)
  )
}

Based on: enter image description here

First answer: Use passwordInput()

From enter image description here

  • Related