有人可以帮助我使用 highcharter 包在“闪亮”应用程序中实现这个出色的 jsfiddle 吗?
https://jsfiddle.net/BlackLabel/nr1y47a9/
我开始写这样的东西,但仍然存在一些问题......
结果如下:https : //pasteboard.co/J7qWN7v.png
library(highcharter)
library(httr)
library(dplyr)
getContent <- function(url) {
content(GET(url))
}
world <- getContent("https://cdn.jsdelivr.net/gh/highcharts/highcharts@v7.0.0/samples/data/world-population.json")
mapdata <- get_data_from_map(download_map_data("custom/world"))
hcmap("custom/world", showInLegend = FALSE) %>%
hc_add_series(name = "Countries", color = '#E0E0E0') %>%
hc_add_series(data= world,type = "mapbubble", name = "Population", joinBy = c("iso-a3", "code3"), color= '#E0E0E0',
minSize = 4, maxSize = "12%",
tooltip = list(pointFormat = '{point.properties.hc-a2}: {point.z} thousands')) %>%
hc_colorAxis(
dataClasses = color_classes(c(0, 50000, 100000, 500000),
colors = c("green","#81c784","#43a047","#1b5e20")#,
# names = c("sg","tf","qsd")
)) …Run Code Online (Sandbox Code Playgroud) 我正在用 highcharter 编写一个闪亮的应用程序。
在我的应用程序中,我想添加一个独立按钮以全屏查看我的图表。
我想我必须在我的示例中添加带有按钮“action_fs”的 JS 代码......这是我的应用程序:
library(shiny)
library(dplyr)
library(highcharter)
ui <- fluidPage(
fluidRow(
actionButton("mybutton","launch"),
br(),
column(width = 6,
uiOutput("button_fullscreen"),
highchartOutput("mygraph")
)
)
)
server = function(input, output) {
mytab <- iris %>% group_by(Species) %>% summarise(mystat=sum(Petal.Length,na.rm = T))
observeEvent(input$mybutton, {
output$button_fullscreen <- renderUI({
actionButton("action_fs","view in full screen")
})
output$mygraph <- renderHighchart({
highchart() %>%
hc_chart(type = "bar") %>%
hc_add_series(data = mytab$mystat, name = "Petal.Length") %>%
hc_xAxis(categories = mytab$Species)
})
})
}
shinyApp(ui = ui, server = server)
Run Code Online (Sandbox Code Playgroud) 我正在寻找从另一个列表重命名 data.frame 中的列。这是我的例子:
mylist <- list(
var1 = "toto",
var2 = "titi"
)
mytable <- data.frame(
var1 = letters[1:3],
var2 = letters[4:6],
var6 = letters[7:9]
)
Run Code Online (Sandbox Code Playgroud)
我尝试过但没有成功:
names(mytable) <- sapply(names(mytable), function(x) mylist$x)
Run Code Online (Sandbox Code Playgroud)
预期结果 :
names(mytable) <- c("toto","titi","var6")
Run Code Online (Sandbox Code Playgroud) 我想根据每个不同的元素拆分列表
mylist <- list("first","first","second")
### What I would like
# A first list
list("first","first")
# A second list
list("second")
Run Code Online (Sandbox Code Playgroud) 使用 {dplyr} 和 {purrr} 我想计算以“eff”开头的每个数字列的总和。
library(dplyr)
library(purrr)
mydf <- tribble(
~categ_21, ~categ_22, ~eff_21, ~eff_22,
"a", "b", 1, 5,
"b", "b", 2, 6,
"c", "c", 3, 7,
"c", "a", 4, 8
)
Run Code Online (Sandbox Code Playgroud)
我想要的是 :
result <- tribble(
~categ, ~eff_21, ~eff_22,
"a", 1, 8,
"b", 2, 11,
"c", 7, 7
)
Run Code Online (Sandbox Code Playgroud)
我尝试过,但它创建了多个 data.frames 并且很长,这就是我想使用 {purrr} 的原因,因为在我真正的工作 data.frame 中,我有比 "21" 和 "22" 更多的列:
mydf %>%
group_by(categ_21) %>%
summarise(total_21 = sum(eff_21))
mydf %>%
group_by(categ_22) %>%
summarise(total_22 = sum(eff_22))
Run Code Online (Sandbox Code Playgroud)
谢谢!