Skip to content

Instantly share code, notes, and snippets.

@dgrapov
Last active October 24, 2016 12:43
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 dgrapov/5895489 to your computer and use it in GitHub Desktop.
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.
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"
}
})
$(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);
shinyUI(pageWithSidebar(
# Application title
headerPanel("Test Header Panel"),
sidebarPanel(
textInput("caption", "Caption:", "Data Summary")
),
mainPanel(
#inputTextarea('exampleTextarea', '',20,35 )
textInput("caption", "Caption:", "Data Summary")
)
))
@withr
Copy link

withr commented Jan 16, 2014

Hi, I run this gist, but nothing expected happens. Have you run it successfully?

@dgrapov
Copy link
Author

dgrapov commented Apr 3, 2014

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