shinyFeedback icon indicating copy to clipboard operation
shinyFeedback copied to clipboard

Icon as label in loadingButton

Open bartekch opened this issue 2 years ago • 8 comments

Is it possible to provide an icon to appear on loadingButton as a label? I've tried this (shinyFeedback 0.4.0):

library(shiny)
library(shinyFeedback)
shinyApp(
  ui = basicPage(
    useShinyFeedback(),
    loadingButton(
      inputId = "l",
      label = HTML(as.character(icon("play")))
    )
  ),
  
  server = function(input, output, session) {
    observeEvent(input$l, {
      Sys.sleep(3)
      resetLoadingButton("l")
    })
  }
)

It works initially, but after reset there is HTML as a text instead of an icon.

It would be great if there is an option to do it, similarly to icon parameter for actionButton.

bartekch avatar Jan 25 '22 17:01 bartekch

@bartekch This can be done with the class & loadingClass arguments, where you provide the icon HTML:

library(shiny)
library(shinyFeedback)
shinyApp(
  ui = basicPage(
    useShinyFeedback(),
    loadingButton(
      inputId = "l",
      label = "",
      class = "fa fa-play btn-primary",
      loadingClass = "fa fa-play"
    )
  ),

  server = function(input, output, session) {
    observeEvent(input$l, {
      Sys.sleep(3)
      resetLoadingButton("l")
    })
  }
)

phoward38 avatar Jan 25 '22 21:01 phoward38

@phoward38 thanks, works!

Although the button looks a bit uglier than those with btn class, image Is it possible to achieve the same button style? I guess I could provide my own CSS, but maybe there is some better option.

bartekch avatar Jan 26 '22 12:01 bartekch

@bartekch You can add the class btn-sm to both class & loadingClass arguments to achieve the same look. I'll keep this issue open to reference when adding an icon argument to loadingButton

phoward38 avatar Jan 26 '22 16:01 phoward38

@phoward38 great, thanks! It works perfectly. Although indeed icon argument would be more convenient, so I'm looking forward to this feature.

bartekch avatar Jan 27 '22 09:01 bartekch

In case this is helpful for anyone else facing a similar issue, I was able to create a nice-looking loading button with a single icon (i.e. minus symbol) with the following R code:

shinyFeedback::loadingButton(
  inputId,
  class = "btn btn-sm fa fa-lg fa-solid fa-minus",
  loadingClass = "btn btn-sm fa fa-lg",
  style = "font-weight: 800;",
  label = "",
  loadingLabel = ""
)

Note that I needed to specify the font-weight style for the icon to be visible - I don't why.

jeffreyhanson avatar Feb 22 '22 03:02 jeffreyhanson

@bartekch @jeffreyhanson I've created a PR for this fix that should be merged shortly, but until then you can use the feature/loadingButton_icon branch.

remotes::install_github("merlinoa/shinyFeedback", ref = "feature/loadingButton_icon")

phoward38 avatar Apr 06 '22 13:04 phoward38

Awesome - thank you very much @phoward38!

jeffreyhanson avatar Apr 07 '22 00:04 jeffreyhanson

@jeffreyhanson No problem! Let me know if you find any bugs using that branch but it's been tested, so the icon argument should work as it does on typical shiny buttons.

@bartekch Leaving issue open until PR is merged.

phoward38 avatar Apr 08 '22 14:04 phoward38