Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

tooltip on shiny R?

I want to have a tool-tip in my Shiny R application. 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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"
    )
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...