I have the following question.
I am trying to learn htmlwidgets by creating bindings to the select2 js library
(https://select2.org/) and bootstrap select library, together with a bunch of utilities to make the creation and use of selectors from R fully featured in both R markdown and shiny.
I do understand the basics of the htmlwidgets now, but I still wonder about one aspect.
I would like my widget to be usable both in R markdown and shiny. In R markdown it would operate as a normal widget. In shiny, however, it should be able to send data back to R. For instance, if the user selects an item from the selector widget, this should be available to R; in other words, the widget needs to send input back to R.
Now I was looking for hints about how to solve this and I found the following:
And from @daattali blog:
Now these two methods of sending input back to shiny from an htmlwidget seem at first sight very different to
me (although I'm just starting with shiny so that might be the reason). I was wondering if you have any suggestion on the best way to implement this. Is it best to create an htmlwidget which in a shiny context also behaves like a custom shiny input, or to use @daattali method?