【问题标题】:R Tooltip Data PointR 工具提示数据点
【发布时间】:2013-07-20 01:35:25
【问题描述】:

我有一个关于 R Shiny 的问题。 所以我想要一个工具提示,当我把鼠标放在点上时,它可以显示数据点的具体信息。 有人知道怎么做吗?

我们非常欢迎示例代码。

【问题讨论】:

  • 你试过什么?看看 rCharts ramnathv.github.io/rCharts。第一个例子似乎就是你要找的
  • 所有带有 rCharts 的 js 库都支持工具提示。您可能还想看看SVGAnnotation,它允许带有网格图形的工具提示。

标签: r tooltip shiny rcharts


【解决方案1】:

我在 Ramnath V 的 rCharts 中看到了这一点,在他的 NYTimes 图形示例中。 rCharts 位于 Shiny 之上。 您可以查看完全可重现的clearly described example here

这段代码就是你所追求的:

require(rCharts)
p1 <- rPlot(SOG ~ yearID, data = team_data, type = 'point', 
  size = list(const = 2), color = list(const = '#888'), 
  tooltip="function(item){return item.SOG +'\n' + item.name + '\n' + item.yearID}"
)
p1$print('chart1')

注意他如何使用 Javascript 函数作为rPlot. 工具提示的参数

另一种选择

您也可以尝试将元素包装在 tags$div()

虽然不是您正在寻找的东西,但在 this related question 中,Joe Cheng 确实建议了这一点,但对于 UI.R。 (不同之处在于,在该示例中,工具提示是静态文本。)

假设你有一个sliderInput

tags$div(title="this static text will show up in the tooltip",
    sliderInput(  # parameters here
    )
)

希望能帮助你前进。

【讨论】:

  • 我们应该使用"#!function(item){return ...}!#"rCharts 0.4.2
【解决方案2】:

您现在也可以使用 ggvis 包进行此操作。见http://ggvis.rstudio.com/

这是您将使用的代码类型,在server.R

library(ggvis)
df %>% ggvis(~x, ~y) %>% layer_points() %>% 
    add_tooltip(function(x) paste0(names(x), ": ", 
                format(x), collapse = "<br />"), "hover") %>%
    bind_shiny("plot_id")

然后在 ui.R 中,放置您使用的绘图:

ggvisOutput("plot_id")

【讨论】:

    猜你喜欢
    • 2017-05-20
    • 1970-01-01
    • 2020-03-29
    • 2021-09-07
    • 2016-02-11
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    • 2018-04-07
    相关资源
    最近更新 更多