Shiny SelectInput and SelectizeInput

扶醉桌前 提交于 2019-12-07 02:25:34

It seems like the current behavior triggers an event on backspace but the input value remains the same. This behavior could actually be an unintended change that happenend when the JavaScript function Shiny.onInputChange was updated. The NEWS on shinys github site claims the following under Version 1.1.

NEW FEATURES

[...]

Introduced two changes to the (undocumented but widely used) JavaScript function Shiny.onInputChange(name, value). First, we changed the function name to Shiny.setInputValue (but don't worry--the old function name will continue to work). Second, until now, all calls to Shiny.onInputChange(inputId, value) have been "deduplicated"; that is, anytime an input is set to the same value it already has, the set is ignored. With Shiny v1.1, you can now add an options object as the third parameter: Shiny.setInputValue("name", value, {priority: "event"}). When the priority option is set to "event", Shiny will always send the value and trigger reactivity, whether it is a duplicate or not.

The current version of selectInput seems to take advantage of this new {priority: "event"} option but that is just speculation.

Workaround

You can adapt your server code to correctly handle this new behavior by deduping the inputs yourself.

dedupedValue <- reactiveVal()
observe({ dedupedValue(input$value) })

Then you use dedupedValue() instead of input$value in the rest of your server code. This will also work with older versions of shiny.

NOTE: If you try to use reactive instead of observe in the above code it will not work.

Long term solution

Maybe it would be best to set this question on hold until the shiny devs took a look at your GitHub issue. As outlined above, the cause of this is probably an interface change on the JavaScript side of shiny. If this indeed created code breaking changes, I am sure the devs will provide a fix to ensure backwards compability.

About req

This is basically unrelated to the issue at hand but came up with your question: If you want req to retrain the old output if the condition is not "truthy", you should call it as

req(condition, cancelOuput = TRUE)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!