I successfully implemented the binding capability of Shiny, but the function is defined in ui.R and any calls from server.R of this new input result in a function not found error.
I am passing session
to server.R (not sure if that makes a difference) and I also created a global.R that simply has the function in it (not sure if I need anything beyond that, because that doesn't even let me call the function in ui.R).
How can I call a custom shiny input function from server.R (specifically in a renderUI
)?
Example code here: (the call to sortList
works fine from ui.R but not server.R)
https://gist.github.com/jpd527/9687359
Here's a patched Gist: https://gist.github.com/trestletech/9691459
There are two major changes here:
sortListInput
function to global.R
. You mention you'd tried that, but it worked swimmingly to expose the function to both server
and UI
.sortListInput
at page creation. You had $( ".sortableList" ).sortable(); $( ".sortableList" ).disableSelection();
in a singleton <script>
in your <head>
, but that's only going to run once at page creation. So dynamically created sortableLists
that get created later would never be initialized. So I added a <script>
chunk to your sortListInput
that will run that code every time you generate a new one. I'm unaware of a cleaner way to do this right now, but perhaps one does/will exist...A couple of things to be aware of:
sortListInputs
each time one gets dynamically created, you need to be sure that that init code is idempotent -- i.e. you're not going to break existing ones when you run that code.