我环顾四周并尝试了一些东西,但我似乎无法让它工作。我希望能够从一些 js 代码更新存储在 input$someVar 中的值。我需要在某个元素上单击,我需要更新 input$someVar 值。我知道有像“updateSelectInput()”这样的函数,但这些函数是从服务器调用的。
我可以物理更改在数据属性中使用并显示的 HTML 中的数据值,但服务器不会将此视为更改,并且 input$someVar 保持不变。
我试过了
var selectBind = Shiny.inputBindings.bindings[5];
selectBind.binding.setValue('#loc', newValue);
Run Code Online (Sandbox Code Playgroud)
在事件处理程序中,其中 #loc 是输入元素的 id,希望我可以这样做,但这给了我一个错误。
有没有办法在ui的java脚本中执行“updateSelectInput()”的功能?
是的,有办法。使用 JavaScript 函数Shiny.onInputChange。
// change the value of an input
document.getElementById("id").value = "value";
// report the change to shiny
Shiny.onInputChange("id", "value");
Run Code Online (Sandbox Code Playgroud)