I am building a shiny application.
I am plotting charts using ggplot.
When I mouseover the points on the graph, I want a tooltip showing one of the columns i
Using plotly
, you can just translate your ggplot
into an interactive version of itself. Just call the function ggplotly
on your ggplot
object:
library(plotly)
data(mtcars)
shinyApp(
ui <- shinyUI(fluidPage(
sidebarLayout(sidebarPanel( h4("Test Plot")),
mainPanel(plotlyOutput("plot1"))
)
)),
server <- shinyServer(
function(input, output) {
output$plot1 <- renderPlotly({
p <- ggplot(data=mtcars,aes(x=mpg,y=disp,color=factor(cyl)))
p <- p + geom_point()
ggplotly(p)
})
}
))
shinyApp(ui, server)
For customizations of what is shown in the tooltip, look e.g. here.