Skip to content

Instantly share code, notes, and snippets.

@ptoche
Created January 29, 2014 17:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptoche/8693347 to your computer and use it in GitHub Desktop.
Save ptoche/8693347 to your computer and use it in GitHub Desktop.
Demo on submit button with pop-up (IN PROGRESS)
# server.R
library("shiny")
shinyServer(
function(session, input, output) {
observe({
if (is.null(input$submit) || input$submit == 0){return()}
js_string <- 'alert("Do you want to submit now?");'
session$sendCustomMessage(type='jsCode', list(value = js_string))
text <- isolate(input$inText)
output$outText <- renderUI({
h4(text)
})
})
}
)
# ui.R
library("shiny")
shinyUI(
basicPage(
tags$head(
tags$style(type='text/css',
"select, textarea, input[type='text'] {margin-bottom: 0px;}"
, "#submit {
color: rgb(255, 255, 255);
text-shadow: 0px -1px 0px rgba(0, 0, 0, 0.25);
background-color: rgb(189,54,47);
background-image: -moz-linear-gradient(center top , rgb(238,95,91), rgb(189,54,47));
background-repeat: repeat-x;
border-color: rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.1) rgba(0, 0, 0, 0.25);
}"
),
tags$script(HTML('
Shiny.addCustomMessageHandler("jsCode",
function(message) {
eval(message.value);
}
);'
))
)
,
textInput(inputId = "inText", label = "", value = "type text here")
,
actionButton(inputId = "submit", label = "Submit")
#
# alternative approach: button with pop-up
# , tags$button("Activate", id = "ButtonID", type = "button", class = "btn action-button", onclick = "return confirm('Are you sure?');" )
,
tags$br()
,
tags$hr()
,
uiOutput("outText")
)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment