2013-05-08 125 views
43

我只想在我的閃亮R應用程序中有一個工具提示。有沒有簡單的方法來實現呢?現在,我正在創建一個密度映射,並且我想要一個簡單的工具提示,將鼠標懸停在滑塊YEAR上方,顯示「單擊此處滑動數年」。
用戶界面:
閃亮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%") 
) 
)) 


服務器代碼:

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

感謝您的幫助。

+1

你能提供更多的信息嗎? http://stackoverflow.com/a/5963610/509782 – harkmug 2013-05-08 20:14:22

回答

48

我想你應該能夠取代這個:

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

與此:

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

非常感謝您的快速回復。 Shiny R真的很酷。我也用Shiny使用Google Motion Chart。你能否爲我提供一種在其中添加/更改工具提示的方式,爲我做一個更多的好處。我沒有在Ui.r和server.r中顯示任何東西,我放了一些代碼,如: 'output $ view_gviz < - renderGvis({chart < - gvisMotionChart(visdata,idvar =「Storm」,timevar =「Year」, ......)'。再一次感謝您的幫助 – Sabin 2013-05-09 17:43:35

+0

如果有人向我提供我的另一篇帖子的提示,類似於以下內容,我將不勝感激: [post](http:// stackoverflow。 com/q/16886892/2167517) – Sabin 2013-06-03 02:37:38

+0

但是有沒有一種方法來設置標題的樣式,以便它在工具提示大於特定大小時滾動? – f1r3br4nd 2013-06-27 16:29:31

36

這是稍微容易和更優雅的方式。

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

您可以添加工具提示中ui.Rserver.R, 另外你也可以使用酥料餅。