JohnCoene / tippy

💬 Tippy.js for Shiny
http://tippy.john-coene.com/
Other
77 stars 2 forks source link

Tippy does not work in reactive context #12

Closed shambhu112 closed 3 years ago

shambhu112 commented 3 years ago

Refer app code here.

The Problem:

  1. Tooltip come once but when selection is changed in the selectize box tooltips disapper.
  2. I tried with renderTippy function also. In this case when selectize is selected nothing renders

Link here for example - https://rstudio.cloud/project/2498232
Code below

library(shiny)
library(tippy)

ui <- fluidPage(

    # Application title
    titlePanel("Tippy Bug"),
    selectizeInput("dataset_selection", "Select Dataset", choices = c("iris" , "airquality")  ,
                   multiple = FALSE, width = 400 , options = NULL ),
    uiOutput("conditional_checkboxes")
  )
server <- function(input, output) {
    names <- list("iris" , "airquality")
    data_r <- reactiveValues(name = names(1) , ds = iris)
    observe({
        data_r$name <- input$dataset_selection
        if(data_r$name == "iris"){
            data_r$ds  <- iris
        }else{
            data_r$ds  <- airquality
        }
    })
   output$conditional_checkboxes <- renderUI({
        pretty_names <- snakecase::to_snake_case(colnames(data_r$ds ))
        dq <- SmartEDA::ExpData(data_r$ds  , type = 2)
        dq$pretty_name <- pretty_names
        lapply(1:nrow(dq), function(i){
            ids <- paste0(data_r$name ,  "_" , i)
            print(ids)
            cb <- create_pretty_checkbox_with_tippy(id = ids , dq[i,])
            })
    })
}
create_pretty_checkbox_with_tippy <- function(id , dq , missing_threshhold = 0.0){
    x <- dq$Per_of_Missing
    missing <- case_when(
        x > missing_threshhold ~ "high" ,
        TRUE  ~ "low")
    if("high" == missing){
        ui <- tippy::with_tippy(
            element =  shinyWidgets::prettyCheckbox( inputId = id , label = dq$pretty_name , value = FALSE , shape = "curve" , status = "danger" , inline = TRUE ) ,
            tooltip = glue::glue("<strong> missing {x * 100}% </strong> of values") ,
            allowHTML = TRUE
        )
    }else{
        ui <-tippy::with_tippy(
            element = shinyWidgets::prettyCheckbox( inputId = id , label = dq$pretty_name , value = TRUE , shape = "curve", status = "success" ,  inline = TRUE) ,
            tooltip = glue::glue("type: {dq$Variable_Type}" ) ,
            allowHTML = TRUE
        )
    }
    ui
}
shinyApp(ui = ui, server = server)
shambhu112 commented 3 years ago

here is a recreatable example of the above app https://rstudio.cloud/project/2498232

JohnCoene commented 3 years ago

The dev version should fix this. I'm very sorry for the extremely late response. Feel free to reopen if it does not work.