shinyCaptcha 文档的示例代码效果很好。
library(shiny)
library(shinyCAPTCHA)
ui <- fluidPage(
recaptchaUI("test", sitekey = "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"),
uiOutput("body")
)
server <- function(input, output, session) {
result <- callModule(recaptcha, "test", secret = "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe")
output$body <- renderUI({
fluidPage(
uiOutput("humansOnly")
)
})
output$humansOnly <- renderUI({
req(result()$success)
tags$h1("For human eyes only!")
})
}
shinyApp(ui, server)
显示:
该应用程序包含按钮,我无法更改它。我想使用自己的按钮,更改标签、位置等,有什么办法可以做到吗?
谢谢!
recaptchaUI
的代码是:
recaptchaUI <- function(id, sitekey = Sys.getenv("recaptcha_sitekey"), ...) {
ns <- NS(id)
tagList(tags$div(
......,
tags$form(
class = "shinyCAPTCHA-form",
action = "?",
method = "POST",
tags$div(class = "g-recaptcha", `data-sitekey` = sitekey, `data-callback` = I("shinyCaptcha")),
tags$br(),
tags$input(type = "submit", ...)
)
))
}
该按钮对应于
tags$input(type = "submit", ...)
。正如您所看到的,它采用省略号 ...
中给出的参数。因此,要更改按钮上显示的文本,您可以使用提交按钮的 value
属性,如下所示:
recaptchaUI(
"test",
sitekey = "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI",
value = "the text you want"
)
要更改样式(颜色等),请使用
style
属性:
recaptchaUI(
"test",
sitekey = "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI",
value = "the text you want",
style = "color: red; background-color: yellow;"
)
要更改按钮的位置,例如将其移到右侧,可以使用 CSS 属性
margin-left
:
recaptchaUI(
"test",
sitekey = "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI",
value = "the text you want",
style = "color: red; background-color: yellow; margin-left: 50px;"
)