我有以下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)
如果我现在翻过一个点,我得到的值如下:(14.5,17.3)。是否有一种简单的方法可以确保这些值显示为:
mpg:12.3 [输入] wt:45.2
答案 0 :(得分:2)
我相信以下是您想要的:
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)
希望这有帮助!