我想在big.mark
图表的tooltip
中格式化数字(添加googleVis
)。昨天我问了这个问题:Hover style of label in googleVis并得到了答案。今天,我遇到了相似的问题 - 区别在于有多个组,所以添加tooltip
不起作用......
我的代码:
ui.R
:
library("shiny")
library("googleVis")
shinyUI(fluidPage(
htmlOutput("wyk")
))
和server.R
:
library("shiny")
library("googleVis")
library("dplyr")
shinyServer(function(input, output) {
d <- iris %>%
group_by(Species) %>%
summarise(ile=1e6*sum(Sepal.Length),
ile2=1e6*sum(Petal.Length))
output$wyk <- renderGvis({
gvisBarChart(d, xvar = "Species", yvar = c("ile", "ile2"),
options=list(legend="top", bar="{groupWidth:'90%'}", height=500))
})
})
我会感激不尽!
答案 0 :(得分:3)
您可以使用roles执行此操作,例如:
library("shiny")
library("googleVis")
d <- iris %>%
group_by(Species) %>%
summarise(ile=1e6*sum(Sepal.Length),
ile2=1e6*sum(Petal.Length))
d$ile.html.tooltip <- prettyNum(d$ile,big.mark = ",",scientific = F)
d$ile2.html.tooltip <- prettyNum(d$ile2,big.mark = ",",scientific = F)
ggvis_plot <- gvisBarChart(d, xvar = "Species", yvar = c("ile","ile.html.tooltip","ile2","ile2.html.tooltip"),
options=list(legend="top", bar="{groupWidth:'90%'}", height=500))
plot(ggvis_plot)