Last active
October 24, 2016 12:43
-
-
Save dgrapov/5895489 to your computer and use it in GitHub Desktop.
Testing Shiny input text area. Based on http://stackoverflow.com/questions/14452465/how-to-create-textarea-as-input-in-a-shiny-webapp-in-r.
Need to put .js in www folder.
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
shinyServer(function(input, output, session) { | |
inputTextarea <- function(inputId, value="", nrows, ncols) { | |
tagList( | |
singleton(tags$head(tags$script(src = "textarea.js"))), | |
tags$textarea(id = inputId, | |
class = "inputtextarea", | |
rows = nrows, | |
cols = ncols, | |
as.character(value)) | |
) | |
output$caption<-"CAPTION" | |
} | |
}) |
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
$(document).on("click", "textarea.inputTextarea", function(evt) { | |
// evt.target is the button that was clicked | |
var el = $(evt.target); | |
// Raise an event to signal that the value changed | |
el.trigger("change"); | |
}); | |
var inputTextareaBinding = new Shiny.InputBinding(); | |
$.extend(inputTextareaBinding, { | |
find: function(scope) { | |
return $(scope).find(".inputTextarea"); | |
}, | |
getValue: function(el) { | |
return $(el).text(); | |
}, | |
setValue: function(el, value) { | |
$(el).text(value); | |
}, | |
subscribe: function(el, callback) { | |
$(el).on("change.inputTextareaBinding", function(e) { | |
callback(); | |
}); | |
}, | |
unsubscribe: function(el) { | |
$(el).off(".inputTextareaBinding"); | |
} | |
}); | |
Shiny.inputBindings.register(inputTextareaBinding); |
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
shinyUI(pageWithSidebar( | |
# Application title | |
headerPanel("Test Header Panel"), | |
sidebarPanel( | |
textInput("caption", "Caption:", "Data Summary") | |
), | |
mainPanel( | |
#inputTextarea('exampleTextarea', '',20,35 ) | |
textInput("caption", "Caption:", "Data Summary") | |
) | |
)) |
This won't work from the Gist. I don't remember if I ever got it to work, but it will need to be structured like a shiny app, with the JS in the WWW folder.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, I run this gist, but nothing expected happens. Have you run it successfully?