Make interactive plot with ggplot2 for Shiny

Hi everybody. I'm working on a shiny app which display a scatterplot on the UI thanks to ggplot(). The x and y variables for this scatterplot belong to a dataset which actually contains others variables.

I would like to make possible to click on one dot of the graph to get access to the others data corresponding to this observation.

First, I need to know if it's possible to make this kind of graph with ggplot(). If the answer is yes, could somebody give me an example on how to do it please ?

Thanks for reading !

Robin

Shiny - Interactive plots (rstudio.com)
Although, generally I would use plotly for interactivity in my charts.

Robin,

In Shiny, you could use ggplot to make your plot, but inside of renderPlotly (and the corresponding plotlyOutput) to make thing interactive.

The built-in dataset mtcars has several columns, but we can interactively just plot two of them:

library(shiny)
library(ggplot)

mycars <- mtcars

ui <- fluidPage(
        fluidRow(
        
          plotlyOutput("myplot")
    ))


server = function(input, output){
  
  
  output$myplot <- renderPlotly({
    ggplot(mtcars,aes(x=cyl, y=mpg))+ geom_point()
  })
}

#Run the app
shinyApp(ui, server)

Hope this helps

Hello nigrahamuk,

Thanks for your answer. I think it will help. I'm starting working on it (and I also use plotly)

Thanks aigan !

Hello cwright. I'm a not sur to get what you want to tell me. Anyway, I got what I needed thanks to nigrahamuk. Thanks for your answer too !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.