假设您在https://lalaland.shinyapps.io/mail-form/上有一个简单的应用程序,用作联系表单。您想在发送电子邮件之前测试发件人不是机器人。这可能看起来像:
全球:
library(shiny)
library(shinyAce)
library(mailR)
Run Code Online (Sandbox Code Playgroud)
用户界面:
ui<-shinyUI(
fluidPage(
fluidRow(
column(2
,textInput("contact_name", "Name*", placeholder = "Ed Snow")
),
column(2, offset = 0
,textInput("contact_email", "Email*", placeholder = "eddie@lubyanka.com")
)
),
fluidRow(
column(4,
aceEditor(outputId = "contact_message", value = "...", fontSize = 13)
)
),
fluidRow(
column(2,
checkboxInput("contact_not_a_robot", "I'm not a robot*", value = FALSE), # !!! <---
actionButton("contact_click_send", "Send")
))
)
)
Run Code Online (Sandbox Code Playgroud)
服务器.R:
server <- shinyServer(function(session,input, output) {
observeEvent(input$contact_click_send, {
if( is.null(input$contact_click_send) || input$contact_click_send==0
|| !input$contact_not_a_robot){ # !!! …Run Code Online (Sandbox Code Playgroud) 我尝试在此处的链接后实现页面刷新按钮.但是当我尝试部署时shinyapp.io,它失败并要求安装V8我已经完成的软件包.该应用程序在机器上正常工作.我使用的代码是:
jsResetCode <- "shinyjs.reset = function() {history.go(0)}",
useShinyjs(), # Include shinyjs in the UI
extendShinyjs(text = jsResetCode), # Add the js code to the page
p(actionButton("reset_button", "Reset Tool"))
Run Code Online (Sandbox Code Playgroud)
在server.R:
observeEvent(input$reset_button, {js$reset()})
Run Code Online (Sandbox Code Playgroud)
有没有办法做到这一点没有shinyjs?