Giter VIP home page Giter VIP logo

Comments (16)

pvictor avatar pvictor commented on June 5, 2024 4

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

from shinywidgets.

mayeromain avatar mayeromain commented on June 5, 2024 2

have you installed the dev version of shinyWidgets?

library(devtools)
install_github("dreamRs/shinyWidgets")

from shinywidgets.

mayeromain avatar mayeromain commented on June 5, 2024 2

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

from shinywidgets.

pvictor avatar pvictor commented on June 5, 2024 2

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)

from shinywidgets.

pvictor avatar pvictor commented on June 5, 2024 1

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

from shinywidgets.

mayeromain avatar mayeromain commented on June 5, 2024 1

Amazing! Very nice features thank you.

Romain

from shinywidgets.

pvictor avatar pvictor commented on June 5, 2024 1

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

from shinywidgets.

mayeromain avatar mayeromain commented on June 5, 2024 1

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

from shinywidgets.

DivadNojnarg avatar DivadNojnarg commented on June 5, 2024 1

I confirm the problem is fixed using:

devtools::install_github("dreamRs/shinyWidgets")

as well as paracetamol ^_^

Cheers

from shinywidgets.

mayeromain avatar mayeromain commented on June 5, 2024

Hello,

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

from shinywidgets.

 avatar commented on June 5, 2024

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:

from shinywidgets.

 avatar commented on June 5, 2024

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

from shinywidgets.

mayeromain avatar mayeromain commented on June 5, 2024

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.

from shinywidgets.

mayeromain avatar mayeromain commented on June 5, 2024

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)

}

from shinywidgets.

DivadNojnarg avatar DivadNojnarg commented on June 5, 2024

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 :)

from shinywidgets.

pvictor avatar pvictor commented on June 5, 2024

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

from shinywidgets.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.