我有以下 Shiny 的应用程序:
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)。有没有一种简单的方法可以确保这些值显示为:
英里/加仑:12.3 [输入] 重量:45.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)
希望这有帮助!
关于r - 更改将鼠标悬停在绘图中的值上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49856253/