闪亮 - 如何在不使用密码输入的情况下将文本输入中的字符替换为***?

发布于 2025-02-12 03:52:37 字数 382 浏览 1 评论 0原文

我在ShinyApp中使用TextInput。 当用户写时,我想看到 - “ ****” - 喜欢密码字段, 但是我不想使用passwordInput,如何仅使用textInput?

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

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)
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情痴 2025-02-19 03:52:37

您可以定义一个自定义函数:

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", class="form-control", value=value,
                 placeholder = placeholder)
  )
}

基于: https:// https:// github.com/rstudio/shiny/blob/main/r/input-password.r

请注意,此实现几乎与passwordInput(请参阅: https:https:// /github.com/rstudio/shiny/blob/main/r/input-password.r ),此外输入还将恢复。

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", class="form-control", value=value,
                 placeholder = placeholder)
  )
}

Based on: https://github.com/rstudio/shiny/blob/main/R/input-password.R

Note that this implementation would be almost identical to passwordInput (see: https://github.com/rstudio/shiny/blob/main/R/input-password.R), besides that input would be restored.

染火枫林 2025-02-19 03:52:37

没有passwordInput()进行更新
textInputicon(来自ShinyWidgets)

library(shiny)

passwordInput_custom <-
  '<div class="form-group shiny-input-container">
        <label class="control-label" id="txt_password-label" for="txt_password"></label>
          <i class="fa fa-user" role="presentation" aria-label="user icon"></i>
        </span>
      <input id="txt_password" type="password" class="form-control" value=""/>
    </div>'

ui <- fluidPage(tagList(HTML(passwordInput_custom)),
                textOutput('psswd'))

server <- function(input, output, session) {
  output$psswd <- renderText({
    input$txt_password
  })
  
}

shinyApp(ui, server)

改编自Heres https://i.sstatic.net/5ipzi.png“ rel =“ nofollow noreferrer”>

第一个答案:
使用passwordInput()

来自 htttps:https:// shiny.rstudio.com/reference/shiny/1.6.0/passwordinput.html

library(shiny)

ui <- fluidPage(
  passwordInput("password", "Password:"),
  actionButton("go", "Go"),
  verbatimTextOutput("value")
)
server <- function(input, output) {
  output$value <- renderText({
    req(input$go)
    isolate(input$password)
  })
}
shinyApp(ui, server)

Update without passwordInput()
Adapted from heres TextInputIcon (from Shinywidgets) with password entry

library(shiny)

passwordInput_custom <-
  '<div class="form-group shiny-input-container">
        <label class="control-label" id="txt_password-label" for="txt_password"></label>
          <i class="fa fa-user" role="presentation" aria-label="user icon"></i>
        </span>
      <input id="txt_password" type="password" class="form-control" value=""/>
    </div>'

ui <- fluidPage(tagList(HTML(passwordInput_custom)),
                textOutput('psswd'))

server <- function(input, output, session) {
  output$psswd <- renderText({
    input$txt_password
  })
  
}

shinyApp(ui, server)

enter image description here

First answer:
Use passwordInput()

From https://shiny.rstudio.com/reference/shiny/1.6.0/passwordInput.html

library(shiny)

ui <- fluidPage(
  passwordInput("password", "Password:"),
  actionButton("go", "Go"),
  verbatimTextOutput("value")
)
server <- function(input, output) {
  output$value <- renderText({
    req(input$go)
    isolate(input$password)
  })
}
shinyApp(ui, server)

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文