'how to reproduce the ggtips demo shiny app

does anyone know how we can reproduce the ggtips' demo shiny app? (https://jcubic.shinyapps.io/ggtips/) - https://github.com/Roche/ggtips.

Below is my script. It works fine when the 'Sepal.Length' and 'Sepal.Width' are selected in X and Y inputs, however, the tooltip doesn't show the values when I change the X and Y variables.

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    selectInput("x_var", label = "X variable", choices = colnames(iris)[1:4], selected = "Sepal.Length"),
    selectInput("y_var", label = "Y variable", choices = colnames(iris)[1:4], selected = "Sepal.Width")
  ),
  dashboardBody(uiOutput("my_plot"))
)

server <- function(input, output) {
  
  output$my_plot <- renderUI({
    plot = iris %>% ggplot(aes(x = .data[[input$x_var]], y = .data[[input$y_var]])) + 
      geom_point(aes(color = Species))
    varDict = list(Sepal.Width = "Width", Sepal.Length = "Length", Species = "Species")
    ggtips::plotWithTooltips(plot, varDict = varDict)
    
  })
   
}

shinyApp(ui = ui, server = server)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source