- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个数据集 df_state 和 df_city。
df_state 有一个数值的总和(net_value_x)。
df_city 在城市级别对数值 (value_x) 进行了分割
这只是德克萨斯州的一个示例:
df_state:
state_abb, net_value_x
.
.
TX 18.94
.
.
df_城市:
state_abb, city, value_x
.
.
TX Dallas 14
TX Houston 2
TX Austin 2.94
.
.
这是我使用 highcharter
中的 hcmap
函数在州级别绘制的代码。
hcmap("countries/us/us-all", data = df_state, value = "net_value_x",
joinBy = c("hc-a2", "code"), name = "net_value_x",
dataLabels = list(enabled = TRUE, format = "{point.name}"),
borderColor = "#FAFAFA", borderWidth = 0.1,
tooltip = list(valueDecimals = 2))
这是我得到的 map 。德克萨斯州的悬停示例数据。
我需要的是进一步深入到城市级别。我也可能在未来获得县级数据。
我在链接中看到类似这样的内容: highchart drilldown
最佳答案
虽然 highcharter 的向下钻取功能很有用,但当您在每个状态都有数据时,它需要在渲染时为每个基础状态加载 map 。我采用的一种方法基本上是在绘制州 map 和县 map 之间切换,如下所示。
## Library
library(shiny)
library(shinyjs)
library(dplyr)
library(highcharter)
library(stringr)
## Load maps at start for speed
maps <- sapply(
X = c("us-all", "us-tx-all"),
simplify = FALSE,
FUN = function(x) { highcharter::download_map_data(paste0("countries/us/", x)) }
)
ui <- shiny::fluidPage(
shinyjs::useShinyjs(),
highcharter::highchartOutput(outputId = "map"),
shiny::uiOutput(outputId = "ui")
)
server <- function(input, output, session) {
## USA map with just TX as example
state_map <- shiny::reactive({
highcharter::highchart() %>%
highcharter::hc_add_series_map(
map = maps[["us-all"]],
df = data.frame(state_abbr = c("TX"), y = c(10)),
joinBy = c("postal-code", "state_abbr"),
value = "y"
) %>%
highcharter::hc_plotOptions(
series = list(
allowPointSelect = TRUE,
events = list(
click = htmlwidgets::JS(
"function(event) {
Shiny.setInputValue(
'geo_click',
event.point.state_abbr,
{priority: 'event'}
);
}"
)
)
)
)
})
## County map
county_map <- shiny::reactive({
highcharter::highchart() %>%
highcharter::hc_add_series_map(
map = maps[[paste0("us-", stringr::str_to_lower(input$geo_click), "-all")]],
df = data.frame(city = c("Gray", "Leon", "Lamb", "Duval"), y = c(1, 4, 2, 3)),
joinBy = c("name", "city"),
value = "y"
)
})
## Set to state map at outset
output$map <- highcharter::renderHighchart({ state_map() })
## If state clicked, add button to go back to state map
output$ui <- shiny::renderUI({
if (!is.null(input$geo_click)) {
shiny::actionButton(
inputId = "geo_button",
label = "Return to USA Map"
)
}
})
## If button clicked, reset input, hide button, and go back to state map
shiny::observeEvent(
eventExpr = input$geo_button,
handlerExpr = {
output$map <- highcharter::renderHighchart({ state_map() })
shinyjs::hide(id = "geo_button")
}
)
## If state clicked, go to county map and show button
shiny::observeEvent(
eventExpr = input$geo_click,
handlerExpr = {
output$map <- highcharter::renderHighchart({ county_map() })
shinyjs::show(id = "geo_button")
}
)
}
shiny::shinyApp(ui = ui, server = server)
关于r - 使用 highcharter 从各州向下钻取美国城市/县 map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48898192/
运行 apache-drill-1.14.0 在 mysql 上测试这个查询并在 0.02 秒内得到结果 在 drill cli 中运行查询失败并出现 AssertionError 查询: produ
我是 Apache Drill 的新手。 场景是这样的: 我有一个 S3 存储桶,我在其中放置了名为 test.csv 的 csv 文件。 我已经按照官方网站的说明安装了 Apache Drill。
我正忙于学习第 2 版《编程:使用 C++ 的原理与实践》(Stroustrup),并且在读取值时遇到了有无空格的问题,然后再次显示它们。 能否请您指出正确的方向,以便我找出结果不同的原因? 代码编译
我是一名优秀的程序员,十分优秀!