RinteRface / shinybulma

🌐 Bulma.io for Shiny
https://rinterface.github.io/shinybulma/
Other
111 stars 15 forks source link

bulmaActionButton works only on second click #21

Closed thothal closed 3 years ago

thothal commented 3 years ago

Issue

You need to hit an bulmaActionButton twice to get it fired.

Reprex

library(shiny)
library(shinybulma)

shinyApp(
   bulmaPage(
      bulmaActionButton("go", "go"), 
      verbatimTextOutput("dbg")),
   function(input, output) output$dbg <- renderPrint({input$go})
)

Reason

The culprit lies in the javascript code for the input binding. We use 2 places to update the element and on top of it we use both data('val') and .val() which are 2 different slots. The order in which shiny runs through the javascript code is as follows:

  1. subscribe here we set data('val') to a new value (1 on first click)
  2. getValue is called then, this function however returns val() which is still zero. shiny does not fire on a zero, so nothing happens.
  3. Eventually, the click event is called where we change val() (this explains why the button works from second clicks onwards)

https://github.com/RinteRface/shinybulma/blob/1389ddd15e7975ccbe9b9631cd16adbe89e59160/inst/js-0.7.2/bulma-button-js.js#L13-L24

Remedy

Remove the unnecessary click event and use the same slot throughout the binding (data('val') for instance, inline with actionButton from shiny itself:

https://github.com/rstudio/shiny/blob/23dbb0b41cc948d25519e78b604413c9bb49cc92/srcjs/input_binding_actionbutton.js#L15-L26

I will create a PR.