Miller Zhu Miller Zhu - 1 year ago 87
R Question

Shiny Responds to Enter

I have a textInput widget, and now whenever I start typing in the widget, shinyApp tries to evaluate the unfinished content in the textInput widget and results in many errors. I'm aware that adding an action Button "Calculate" would easily solve the problem. However, my app does not have space left for one more button. So, I'd like to know if there's a way that the textInput widget would "listen" to a keyboard event, such as when the user hits "Enter?" Thanks in advance!

Answer Source

In your case, the problem is reactive programming and this is the reason that you need something to manage this situation. My recommendation is to use observer pattern or validate function.

  • Observer pattern: shiny implements the observer pattern which is useful to act when an event happens in an object (it can be a click in a button, new value in an input...).

  • Validate function: the functionality of this process is similar to an if/else statement. Indeed, there is need what is the if to check the parameter, if the values are wrong, there will be an error message.

To know how to use observe pattern and the validate function, click on the previous link (in the Shiny website is everything explained).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download