Created
January 29, 2014 17:58
-
-
Save ptoche/8693347 to your computer and use it in GitHub Desktop.
Demo on submit button with pop-up (IN PROGRESS)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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) | |
}) | |
}) | |
} | |
) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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