ToolTip when you mouseover a ggplot on shiny

前端 未结 4 1137
梦毁少年i
梦毁少年i 2020-12-04 18:16

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

4条回答
  •  独厮守ぢ
    2020-12-04 19:03

    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.

提交回复
热议问题