In some instances, you will want to send data from JS client to the R server. Here is a basic example using javascript's Shiny.onInputChange
function:
library(shiny)
runApp(
list(
ui = fluidPage(
# create password input
HTML('<input type="password" id="passwordInput">'),
# use jquery to write function that sends value to
# server when changed
tags$script(
'$("#passwordInput").on("change",function() {
Shiny.onInputChange("myInput",this.value);
})'
),
# show password
verbatimTextOutput("test")
),
server = function(input, output, session) {
# read in then show password
output$test <- renderPrint(
input$myInput
)
}
)
)
Here we create a password input with id passwordInput
. We add a Javascript function on the UI that reacts to changes in passwordInput
, and sends the value to the server using Shiny.onInputChange
.
Shiny.onInputChange
takes two parameters, a name for the input$*name*
, plus a value for input$*name*
Then you can use input$*name*
like any other Shiny input.