Although the use of renderUI and uiOutput could solve my problem, I do not want to redo the input widget.
See the example below, where the textInput text introduced by the user is replaced by asterisks except the last character as he/she is typing.
Notice, from the example, that when the user types on the second textInput he/she must click every time in textInput window to type a new character, while this is not necessary for the first textInput.
In my case, I would like textAreaInput height fits the text while the user is typing. So, every linebreak "cols" attribute increases a unit, without having to click every time on the textInputArea window, which may very tedious for the user.
library(shiny)
ui <- fluidPage(
textInput("pass", "Enter password (update)", ""),
uiOutput("passui")
)
server <- function(input, output, session){
observeEvent(input$pass,{
if (length(input$pass)){
pass <- strsplit(input$pass,split="")[[1]]
pass[-length(pass)] <- "*"
ast <- paste(pass, collapse="")
} else {
ast <- ""
}
updateTextInput(session, "pass", value=ast)
})
output$passui <- renderUI({
if (length(input$pass2)){
pass <- strsplit(input$pass2,split="")[[1]]
pass[-length(pass)] <- "*"
ast <- paste(pass, collapse="")
} else {
ast <- ""
}
textInput("pass2", "Enter password (renderUI)", value=ast)
})
}
shinyApp(ui, server)