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

sendSweetAlert no html option anymore #48

Closed
mayeromain opened this issue Jan 29, 2018 · 16 comments
Closed

sendSweetAlert no html option anymore #48

mayeromain opened this issue Jan 29, 2018 · 16 comments

Comments

@mayeromain
Copy link

@mayeromain mayeromain commented Jan 29, 2018

I was wondering why the HTML = T option on the sendSweetAlert function has been remove? Is there a solution to use the same code as before to have some html text display in the sweet alert?
Also, is it possible not to close the alert when we click outside the popup?
Thanks

@pvictor
Copy link
Member

@pvictor pvictor commented Jan 29, 2018

Hello,
This option is no longer available in sweetalert 2.0, I'll look to find an alternative solution.

I added argument closeOnClickOutside to prevent closing when clicking outside, please install package from Github :

shinyApp(
  ui = fluidPage(
    tags$h1("Click the button"),
    actionButton(
      inputId = "success",
      label = "Launch a success sweet alert"
    )
  ),
  server = function(input, output, session) {
    observeEvent(input$success, {
      sendSweetAlert(
        session = session,
        title = "Success !!",
        text = "All in order",
        type = "success", 
        closeOnClickOutside = FALSE
      )
    })
  }
)
@mayeromain
Copy link
Author

@mayeromain mayeromain commented Jan 29, 2018

Hello,

thank you very much for your update and thanks for the package it is very useful!

@pvictor
Copy link
Member

@pvictor pvictor commented Jan 29, 2018

With a little JavaScript, argument html is back !
Glad you find the package useful :)

Try :

library("shiny")
library("shinyWidgets")

shinyApp(
  ui = fluidPage(
    tags$h1("Click the button"),
    actionButton(
      inputId = "sw_html",
      label = "Sweet alert with HTML"
    )
  ),
  server = function(input, output, session) {
    observeEvent(input$sw_html, {
      sendSweetAlert(
        session = session,
        title = "Success !!",
        text = tags$span(
          "In", tags$b("bold"), "and", tags$em("italic"),
          tags$br(),
          "and",
          tags$br(),
          "line",
          tags$br(),
          "breaks"
        ), 
        html = TRUE,
        type = "success"
      )
    })
  }
)

Victor

@mayeromain
Copy link
Author

@mayeromain mayeromain commented Jan 30, 2018

Amazing! Very nice features thank you.

Romain

@pvictor pvictor closed this Jan 30, 2018
@ghost
Copy link

@ghost ghost commented Jan 30, 2018

just updated R and shinyWidgets, this example throws:
Warning: Error in sendSweetAlert: unused argument (html = FALSE)
Stack trace (innermost first):
68: observeEventHandler [#11]
4:
3: do.call
2: print.shiny.appobj
1:

@mayeromain
Copy link
Author

@mayeromain mayeromain commented Jan 30, 2018

have you installed the dev version of shinyWidgets?

library(devtools)
install_github("dreamRs/shinyWidgets")
@ghost
Copy link

@ghost ghost commented Jan 30, 2018

yes just did, still same result

sessionInfo()
R version 3.4.3 (2017-11-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=Dutch_Netherlands.1252 LC_CTYPE=Dutch_Netherlands.1252 LC_MONETARY=Dutch_Netherlands.1252 LC_NUMERIC=C
[5] LC_TIME=Dutch_Netherlands.1252

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] shinyWidgets_0.4.1 shiny_1.0.5

loaded via a namespace (and not attached):
[1] compiler_3.4.3 R6_2.2.2 htmltools_0.3.6 tools_3.4.3 Rcpp_0.12.15 jsonlite_1.5 digest_0.6.14 xtable_1.8-2 httpuv_1.3.5 mime_0.5

@mayeromain
Copy link
Author

@mayeromain mayeromain commented Jan 30, 2018

the dev version is shinyWidgets_0.4.1.910. Try to remove it and re-install using the code I provided above.

@mayeromain
Copy link
Author

@mayeromain mayeromain commented Feb 12, 2018

Have you plan to do the same on the confirmSweetAlert function? I realy like the way it can be customized using HTML and the possibility to force a click from the user.

@pvictor
Copy link
Member

@pvictor pvictor commented Feb 12, 2018

Yes, it works in the latest version. I tried to go further by passing input/output, it seems to work but I don't know if it is very robust. Thanks for the improvement suggestion, it was cool to do.

If you want to try it :

library("shiny")
library("shinyWidgets")
library("ggplot2")

shinyApp(
  ui = fluidPage(
    tags$h1("Click the button"),
    actionButton(
      inputId = "sw_html",
      label = "Sweet alert with ggplot"
    ),
    tags$style(".swal-modal {width: 70%;}")
  ),
  server = function(input, output, session) {
    observeEvent(input$sw_html, {
      sendSweetAlert(
        session = session,
        title = "Yay an histogram!",
        text = tags$div(
          plotOutput(outputId = "plot"),
          sliderInput(
            inputId = "slider", label = "Number of bins",
            min = 20, max = 90, value = 60, width = "100%"
          )
        ),
        html = TRUE
      )
    })
    output$plot <- renderPlot({
      ggplot(diamonds, aes(carat)) +
        geom_histogram(bins = input$slider)
    })
  }
)
@mayeromain
Copy link
Author

@mayeromain mayeromain commented Feb 12, 2018

you rock! This is really a good package thanks for all your updates.

@mayeromain
Copy link
Author

@mayeromain mayeromain commented Feb 12, 2018

maybe it's a problem on my side but the htlm = T option on the confirmSweetAlert and the sendSweetAlert didn't seem to work anymore on version 0.4.1.950
Here is a minimal example:

library("shiny")
library("shinyWidgets")


ui <- fluidPage(
  actionButton(
    inputId = "go",
    label = "Launch confirmation dialog"
  )
)

server <- function(input, output, session) {
  
  observeEvent(input$go, {
    sendSweetAlert(
      session = session, type = "warning",
      title = "Is the HTML </br>Working or not?",html =  T
    )
  })
  
}

shinyApp(ui = ui, server = server)

}
@pvictor
Copy link
Member

@pvictor pvictor commented Feb 12, 2018

You have to use argument text to use HTML, and if yous use raw HTML, you'll have to escape it with HTML like this :

library("shiny")
library("shinyWidgets")


ui <- fluidPage(
  actionButton(
    inputId = "go",
    label = "Launch confirmation dialog"
  )
)

server <- function(input, output, session) {
  
  observeEvent(input$go, {
    sendSweetAlert(
      session = session, type = "warning", title = NULL,
      text = HTML("Is the HTML </br>Working or not?"), html =  TRUE
    )
  })
  
}

shinyApp(ui = ui, server = server)
@DivadNojnarg
Copy link
Contributor

@DivadNojnarg DivadNojnarg commented Mar 29, 2018

Hi Victor!
I noticed that it does not work on shiny-server pro:

Warning: Error in sendSweetAlert: unused argument (html = FALSE)
Stack trace (innermost first):
    65: observeEventHandler [/srv/shiny-server/case_studies_app_V3.2/server.R#485]
     1: runApp

no matter if it is set to TRUE or FALSE

Removing sendSweetAlert from the observeEvent would solve the problem. But this is not what I want to do :)

@pvictor
Copy link
Member

@pvictor pvictor commented Mar 29, 2018

Hello David,
Yes I removed the arg on the last CRAN release, bad idea...
It's back in the dev version, try re-install the package from Github.
I'll try release to CRAN tomorrow.

Victor

@DivadNojnarg
Copy link
Contributor

@DivadNojnarg DivadNojnarg commented Mar 29, 2018

I confirm the problem is fixed using:

devtools::install_github("dreamRs/shinyWidgets")

as well as paracetamol ^_^

Cheers

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

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.