yonicd / slickR

slick carousel htmlwidget for R
https://yonicd.github.io/slickR/
Other
159 stars 14 forks source link

shinyglide Conflicts with slickR #24

Closed JonP-16 closed 5 years ago

JonP-16 commented 5 years ago

Hi!

I posted this to the shinyglide github. It seems that whenever slickR is used, the 'glide' content of the modal gets very squished and unreadable. I'm not sure if this is your package or if it's shinyglide's package but I thought I should let you know.

library(shiny)
library(shinyglide)
library(slickR)

ui <- fixedPage(  
  fluidRow(
    slickROutput("slickr", width="500px")
  ) 
)

server <- function(input, output, session) {

  showModal(
    modalDialog(
      title = "Startup assistant",
      easyClose = FALSE,
      footer = NULL,
      glide(
        screen(
          p("Let's initialize some values, would you ?")
        ),
        screen(
          p("First, please select a mean value"),
          numericInput("mean_modal", "Mean", value = 0)
        ),
        screen(
          p("Then, please select a sd value"),
          numericInput("sd_modal", "SD", value = 0)
        )
      )
    )
  )

  png('image1.png'); plot(rnorm(100)); dev.off()
  png('image2.png'); plot(runif(100)); dev.off()
  output$slickr <- renderSlickR({
    slickR(c("image1.png",
             "image2.png"),
           height='400px',width='100%')
  })
  }

shinyApp(ui, server)
juba commented 5 years ago

I believe this problem has now been fixed in shinyglide, and it's not directly related to slickR, so this issue might be closed.

yonicd commented 5 years ago

for reference this is a simpler way to use slickR with plot outputs (without using the device to temporarily convert to pngs)

server <- function(input, output, session) {

  showModal(
    modalDialog(
      title = "Startup assistant",
      easyClose = TRUE,
      footer = NULL,
      glide(
        screen(
          p("Let's initialize some values, would you ?")
        ),
        screen(
          p("First, please select a mean value"),
          numericInput("mean_modal", "Mean", value = 0)
        ),
        screen(
          p("Then, please select a sd value"),
          numericInput("sd_modal", "SD", value = 1)
        )
      )
    )
  )

  observeEvent(c(input$mean_modal,input$sd_modal),{

    plotsToSVG <- replicate(2,expr = {
      svglite::xmlSVG({plot(rnorm(20,input$mean_modal,input$sd_modal))
      },standalone=TRUE)},simplify = FALSE)

    imgs <- sapply(plotsToSVG,function(sv){paste0("data:image/svg+xml;utf8,",as.character(sv))})

    output$slickr <- renderSlickR({slickR(imgs)})  
  })

}