[英]tooltip on shiny R?
I want to have a tool-tip in my Shiny
R
application.我想在我的
Shiny
R
应用程序中有一个工具提示。 Is there any easy way to achieve that?有什么简单的方法可以实现吗? For now, I am creating a density map and I want a simple tool-tip showing "click here to slide through years" while hovering the mouse over slider YEAR.
现在,我正在创建一个密度 map,我想要一个简单的工具提示,显示“单击此处以滑过几年”,同时将鼠标悬停在 slider YEAR 上。
User Interface:用户界面:
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Density Map"),
sidebarPanel(
sliderInput("slider_year", "YEAR:",
min = 2001, max = 2011, value = 2009,
format="####", locale="us"
)
)
),
mainPanel(
plotOutput("event_heatmap_map", width = "100%", height = "100%")
)
))
Server Code:服务器代码:
library(shiny)
library(ggmap)
library(ggplot2)
mydata <- read.csv("/var/shiny-server/www/dMetrics.csv")
shinyServer(function(input, output) {
output$event_heatmap_map <- renderPlot(width = "auto", height = 640,{
slice_year <- mydata[mydata$YEAR==input$slider_year,]
map <- get_map(c(lon = -55.3632715, lat = 31.7632836), zoom = 3, source = 'google', maptype = c("terrain"), messaging = FALSE, color = 'color')
world <- ggmap(map)
world <- world + stat_density2d(data = slice_year, aes(x = WEST, y = NORTH, fill = ..level.., alpha = ..level..), show_guide = FALSE, geom = "polygon", na.rm = TRUE) + scale_fill_gradient(name="Density", low="maroon", high="yellow", guide = 'colorbar')
plot(world)
})
})
Thanks for the help.谢谢您的帮助。
I think you should be able to replace this: 我认为你应该能够取代这个:
sliderInput("slider_year", "YEAR:",
min = 2001, max = 2011, value = 2009,
format="####", locale="us"
)
with this: 有了这个:
tags$div(title="Click here to slide through years",
sliderInput("slider_year", "YEAR:",
min = 2001, max = 2011, value = 2009,
format="####", locale="us"
)
)
This is slightly easier and more elegant way. 这稍微容易一些,更优雅。
library(shinyBS) # Additional Bootstrap Controls
## From ui.R: Adds a tooltip to element with inputId = "someInput"
## with text, "This is an input.", that appears to the left on hover.
bsTooltip(id = "someInput", title = "This is an input",
placement = "left", trigger = "hover")
## From server.R: Add the same tooltip as above
addTooltip(session, id = "someInput", title = "This is an input.",
placement = "left", trigger = "hover")
You can add the Tooltip in ui.R
or server.R
, Additional you can also use Popover. 您可以在
ui.R
或server.R
添加工具提示,其他您也可以使用Popover。
Nowadays it's possible to wrap ggplot visualizations around plot_ly, and plotly has a native component (precissely named tootip) which will serve the purpose you're looking for:现在可以围绕 plot_ly 包装 ggplot 可视化,plotly 有一个本地组件(精确命名为 tootip),它将满足您正在寻找的目的:
library(plotly)
#install.packages("gapminder")
library(gapminder)
p <- ggplot(gapminder, aes(x = gdpPercap, y = lifeExp, color = continent, text = paste("country:", country))) +
geom_point(alpha = (1/3)) + scale_x_log10()
fig <- ggplotly(p)
fig
Also, refer to: https://plotly-r.com/controlling-tooltips.html for a more detailed explanation.另请参阅: https://plotly-r.com/controlling-tooltips.html以获得更详细的解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.