2013-05-08 13 views
43

Voglio semplicemente avere un suggerimento sulla mia lucida applicazione R. C'è un modo semplice per raggiungerlo? Per ora, sto creando una mappa della densità e voglio un semplice suggerimento che mostri "clicca qui per scorrere tra gli anni" mentre passi con il mouse sopra l'ANNO del cursore.
Interfaccia utente :
tooltip su lucido R?

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


Codice Server:

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

Grazie per l'aiuto.

+1

Potrebbe fornire ulteriori informazioni? http://stackoverflow.com/a/5963610/509782 – harkmug

risposta

48

penso che si dovrebbe essere in grado di sostituire questo:

sliderInput("slider_year", "YEAR:", 
      min = 2001, max = 2011, value = 2009, 
      format="####", locale="us" 
) 

con questo:

tags$div(title="Click here to slide through years", 
    sliderInput("slider_year", "YEAR:", 
       min = 2001, max = 2011, value = 2009, 
       format="####", locale="us" 
    ) 
) 
+0

Grazie mille per la rapida risposta. Shiny R è davvero fantastico. Sto anche usando Google Motion Chart con Shiny. Puoi per favore fare un altro favore per me fornendomi un modo per aggiungere/cambiare tool-tip lì dentro. Non ho mostrato nulla in Ui.r e in server.r Ho messo alcuni codici come: 'output $ view_gviz <- renderGvis ({chart <- gvisMotionChart (visdata, idvar =" Storm ", timevar =" Year ", ......) 'Grazie ancora per l'aiuto – Sabin

+0

Sarò grato se qualcuno mi fornirà il suggerimento per il mio altro post, simile a questo: [post] (http: // stackoverflow. it/q/16886892/2167517) – Sabin

+0

Ma c'è un modo per dare uno stile al titolo in modo che scorra se il suggerimento è più grande di una certa dimensione? – f1r3br4nd

36

Questo è il modo un po 'più facile e più elegante.

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

è possibile aggiungere i Tooltip in ui.R o server.R, aggiuntive che si possono anche usare Popover.