dreamRs / shinyWidgets

shinyWidgets : Extend widgets available in shiny
https://dreamrs.github.io/shinyWidgets/
GNU General Public License v3.0
826 stars 153 forks source link

pickerInput still doesnt work #261

Closed sbridel closed 7 months ago

sbridel commented 4 years ago

Hi.

I am facing the pickerInput bug in my shiny app. First, I checked the example code below and everything is working fine.

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

ui <- fluidPage(
  tags$h2("Dropdown Button"),
  br(),
  dropdown(

    tags$h3("List of Input"),

    pickerInput(inputId = 'xcol2',
                label = 'X Variable',
                choices = names(iris),
                options = list(`style` = "btn-info")),

    pickerInput(inputId = 'ycol2',
                label = 'Y Variable',
                choices = names(iris),
                selected = names(iris)[[2]],
                options = list(`style` = "btn-warning")),

    sliderInput(inputId = 'clusters2',
                label = 'Cluster count',
                value = 3,
                min = 1, max = 9),

    style = "unite", icon = icon("gear"),
    status = "danger", width = "300px",
    animate = animateOptions(
      enter = animations$fading_entrances$fadeInLeftBig,
      exit = animations$fading_exits$fadeOutRightBig
    )
  ),

  plotOutput(outputId = 'plot2')
)

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

  selectedData2 <- reactive({
    iris[, c(input$xcol2, input$ycol2)]
  })

  clusters2 <- reactive({
    kmeans(selectedData2(), input$clusters2)
  })

  output$plot2 <- renderPlot({
    palette(c("#E41A1C", "#377EB8", "#4DAF4A",
              "#984EA3", "#FF7F00", "#FFFF33",
              "#A65628", "#F781BF", "#999999"))

    par(mar = c(5.1, 4.1, 0, 1))
    plot(selectedData2(),
         col = clusters2()$cluster,
         pch = 20, cex = 3)
    points(clusters2()$centers, pch = 4, cex = 4, lwd = 4)
  })

}

shinyApp(ui = ui, server = server) 

but in my app, the same code doesn't work anymore. I can't figure out if it's because something is missing like a package depedencies or the fact i'm using the same code inside tab item?

EDIT = even adding tabItems on this example code don't reproduce the bug... I try to load all the same packages as my app but still working.

EDIT 2 = splitting this code in ui.R and server.R doesnt reproduce the bug... I don't know what happens

sbridel commented 4 years ago

Ok I think i have found it out....

It happens when in server I load HTML file

SERVER.R
  getPage_1<-function() {
    return(includeHTML("www/Overview.html"))
  }
  output$overview <-renderUI({getPage_1()})
  getPage_2<-function() {
    return(includeHTML("www/FAQ.html"))
  }
  output$faq <-renderUI({getPage_2()})
  getPage_3<-function() {
    return(includeHTML("www/credits.html"))
  }
  output$AF <-renderUI({getPage_3()})
}

UI.R

      tabItem(tabName = "FAQ",
              htmlOutput("faq")%>% withSpinner(color="#dc322f",size = 2)
      ),
##### Credits ----------------------------------------------------------------
      tabItem(tabName = "Credits",
              htmlOutput("AF")%>% withSpinner(color="#dc322f",size = 2)
      )

I don't know why but the HTML things seems to freeze the pickerInput. I had already many issues with loading HTML files in the app. Maybe I have to find a better way to do this.

pvictor commented 4 years ago

Hello, How do you produce the html files ? That can be an html dependency issue..

Victor

sbridel commented 4 years ago

Usually I do it with R markdown and knittr

p-schaefer commented 2 years ago

Was there ever a solution to this? I have the same problem.

pvictor commented 2 years ago

@p-schaefer , can you provide a reproducible example ?

p-schaefer commented 2 years ago

Unfortunately, I can't. When I try to make a small reproducible example it works, but in by big complicated dashboard (which is behind a vpn), whenever I add includeHTML() into the UI, the pickerInputs disappear.