I have the following Shiny Application:
library(shiny)
library(plotly)
ui <- fluidPage(
plotlyOutput("plot")
)
server <- function(input, output) {
# renderPlotly() also understands ggplot2 objects!
output$plot <- renderPlotly({
plot_ly(mtcars, x = ~mpg, y = ~wt)
})
}
shinyApp(ui, server)
If I now hoover over a point I get values like: (14.5, 17.3). Is there an easy way to make sure these values appear as:
mpg: 12.3 [enter]
wt: 45.2
Answer
I believe the following does what you want:
library(shiny)
library(plotly)
ui <- fluidPage(
plotlyOutput("plot")
)
server <- function(input, output) {
# renderPlotly() also understands ggplot2 objects!
output$plot <- renderPlotly({
plot_ly(mtcars,
x = ~mpg,
y = ~wt,
hoverinfo="text",
text = ~paste0("mpg: ", mpg, "\nwt: ", wt))
})
}
shinyApp(ui, server)
Hope this helps!
No comments:
Post a Comment