当前位置:  开发笔记 > 编程语言 > 正文

闪亮的R上的工具提示?

如何解决《闪亮的R上的工具提示?》经验,为你挑选了2个好方法。

我希望在我的Shiny R应用程序中有一个工具提示.有没有简单的方法来实现这一目标?现在,我正在创建一个密度图,我想要一个简单的工具提示,显示"点击这里滑过几年",同时将鼠标悬停在滑块YEAR上.

用户界面:

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> Joe Cheng..:

我认为你应该能够取代这个:

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



2> 小智..:

这稍微容易一些,更优雅.

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.R或者server.R,您也可以使用Popover.

推荐阅读
拾味湖
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有