Created
October 25, 2013 22:02
-
-
Save xiaodaigh/7162506 to your computer and use it in GitHub Desktop.
R Shiny Password Input
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
| library(shiny) | |
| shinyServer(function(input, output, session) { | |
| # Partial example | |
| output$meh <- renderPrint({ | |
| print("Meh --- ") | |
| print(input$myTextInput ) | |
| print(input$passInput ) | |
| }) | |
| }) |
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
| library(shiny) | |
| passwordTextInput <- function (inputId, label, value = "") { | |
| tagList(tags$label(label, `for` = inputId), tags$input(id = inputId, | |
| type = "password", value = value,class="passTextInput")) | |
| } | |
| code = HTML(" <script> var myTextInputBinding = new Shiny.InputBinding(); | |
| $.extend(myTextInputBinding, { | |
| find: function(scope) { | |
| return $(scope).find('.passTextInput'); | |
| }, | |
| getId: function(el) { | |
| //return InputBinding.prototype.getId.call(this, el) || el.name; | |
| return $(el).attr('id') | |
| }, | |
| getValue: function(el) { | |
| return el.value; | |
| }, | |
| setValue: function(el, value) { | |
| el.value = value; | |
| }, | |
| subscribe: function(el, callback) { | |
| $(el).on('keyup.textInputBinding input.textInputBinding', function(event) { | |
| callback() | |
| }); | |
| }, | |
| unsubscribe: function(el) { | |
| $(el).off('.myTextInputBinding'); | |
| }, | |
| receiveMessage: function(el, data) { | |
| if (data.hasOwnProperty('value')) | |
| this.setValue(el, data.value); | |
| if (data.hasOwnProperty('label')) | |
| $(el).parent().find('label[for=' + el.id + ']').text(data.label); | |
| $(el).trigger('change'); | |
| }, | |
| getState: function(el) { | |
| return { | |
| label: $(el).parent().find('label[for=' + el.id + ']').text(), | |
| value: el.value | |
| }; | |
| }, | |
| getRatePolicy: function() { | |
| return { | |
| policy: 'debounce', | |
| delay: 250 | |
| }; | |
| } | |
| }); | |
| Shiny.inputBindings.register(myTextInputBinding, 'shiny.myTextInput');</script>") | |
| shinyUI( | |
| basicPage( | |
| code | |
| ,textInput("myTextInput","My text input") | |
| ,passwordTextInput("passInput","My pass input") | |
| ,textOutput("meh") | |
| ,HTML('<script src="https://gist.github.com/xiaodaigh/7162506.js"></script>') | |
| )) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I guess you can avoid copying the input binding code by extending the existing
shiny.textInputbinding, e.g.Since the major thing you want to modify is the
findmethod (there may be a couple other places that you need to modify as well).