When is getState used in Shiny input bindings?


When is getState used in Shiny input bindings? My assumption is it needs to be included in a custom input if the input is to be bookmarked, but I'm not sure as I can't find anything that discusses this. Thanks for your help!

  • Drew


For context, in the article How to create custom input bindings, it states under Additional methods:

In addition to the previously discussed methods, several other JavaScript methods can be added to your input binding object, notably; getId, getState, getRatePolicy, receiveMessage and unsubscribe. These are discussed in the various references provided and are not further discussed here.

The custom input bindings example from the Shiny gallery has this method - see below (truncated for brevity):

var urlInputBinding = new Shiny.InputBinding();
$.extend(urlInputBinding, {
   // This returns a full description of the input state.
   // Note that some inputs may be too complex for a full description of the
   // state to be feasible.
   getState: function(el) {
     return {
       label: $(el).parent().find('label[for="' + $escape(el.id) + '"]').text(),
       value: el.value

I did a thorough (I think) search of the Shiny codebase and only saw getState when the input is being created, so I'm thinking now it might just be for testing/debugging purposes and not required for bookmarking state?


Excellent question! The getState() method was added in this pull request with the purpose of using it for testing Shiny's JavaScript code. https://github.com/rstudio/shiny/pull/139

However, that test system is no longer used by Shiny, and I don't think getState() is used anywhere now.


Awesome, thanks for the clarification, Winston!

closed #5

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.