Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

64 Zeilen
2.4KB

  1. // Ref: https://shiny.rstudio.com/articles/building-inputs.html
  2. // Ref: https://github.com/rstudio/shiny/blob/master/srcjs/input_binding.js
  3. const typingSpeed = new Shiny.InputBinding();
  4. $.extend(typingSpeed, {
  5. find: function(scope) {
  6. // Specify the selector that identifies your input. `scope` is a general
  7. // parent of your input elements. This function should return the nodes of
  8. // ALL of the inputs that are inside `scope`. These elements should all
  9. // have IDs that are used as the inputId on the server side.
  10. return scope.querySelectorAll(".typing-speed textarea");
  11. },
  12. getValue: function(el) {
  13. // For a particular input, this function is given the element containing
  14. // your input. In this function, find or construct the value that will be
  15. // returned to Shiny. The ID of `el` is used for the inputId.
  16. return el.value;
  17. },
  18. setValue: function(el, value) {
  19. // This method is used for restoring the bookmarked state of your input
  20. // and allows you to set the input's state without triggering reactivity.
  21. // Basically, reverses .getValue()
  22. // e.g.; el.value = value
  23. console.error('typingSpeed.setValue() is not yet defined');
  24. },
  25. receiveMessage: function(el, data) {
  26. // Given the input's container and data, update the input
  27. // and its elements to reflect the given data.
  28. // The messages are sent from R/Shiny via
  29. // R> session$sendInputMessage(inputId, data)
  30. console.error('typingSpeed.receiveMessage() is not yet defined');
  31. // If you want the update to trigger reactivity, trigger a subscribed event
  32. // $(el).trigger("keyup")
  33. },
  34. subscribe: function(el, callback) {
  35. // Listen to events on your input element. The following block listens to
  36. // the change event, but you might want to listen to another event.
  37. // Repeat the block for each event type you want to subscribe to.
  38. $(el).on("keyup.typingSpeed", function(e) {
  39. // Use callback() or callback(true).
  40. // If using callback(true) the rate policy applies,
  41. // for example if you need to throttle or debounce
  42. // the values being sent back to the server.
  43. callback();
  44. });
  45. },
  46. getRatePolicy: function() {
  47. return {
  48. policy: 'debounce', // 'debounce', 'throttle' or 'direct' (default)
  49. delay: 100 // milliseconds for debounce or throttle
  50. };
  51. },
  52. unsubscribe: function(el) {
  53. $(el).off(".typingSpeed");
  54. }
  55. });
  56. Shiny.inputBindings.register(typingSpeed, 'js4shiny.typingSpeed');