Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Icon as label in loadingButton #60

Open
bartekch opened this issue Jan 25, 2022 · 8 comments · May be fixed by #64
Open

Icon as label in loadingButton #60

bartekch opened this issue Jan 25, 2022 · 8 comments · May be fixed by #64

Comments

@bartekch
Copy link

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.

@phoward38 phoward38 self-assigned this Jan 25, 2022
@phoward38
Copy link
Collaborator

@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")
    })
  }
)

@bartekch
Copy link
Author

@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.

@phoward38
Copy link
Collaborator

@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

@bartekch
Copy link
Author

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

@jeffreyhanson
Copy link

jeffreyhanson commented Feb 22, 2022

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.

@phoward38 phoward38 linked a pull request Apr 5, 2022 that will close this issue
@phoward38
Copy link
Collaborator

@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")

@jeffreyhanson
Copy link

Awesome - thank you very much @phoward38!

@phoward38
Copy link
Collaborator

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants