我正在处理一个不是股市数据的时间序列。我想在R中使用highcharter来进行交互式可视化。我暂时做了一个这样的图表:
虚拟数据
library(tidyverse)
library(highcharter)
data(economics_long, package = "ggplot2")
economics_long2 <- filter(economics_long,
variable %in% c("pop", "uempmed", "unemploy"))
hchart(economics_long2, "line", hcaes(x = "date", y = "value01", group = "variable"))我想知道,有没有办法在这个图表的顶部添加一个日期过滤器,就像highcharter中type = 'stock‘图表中的日期过滤器一样。类似于此图的内容:

发布于 2018-10-16 04:17:01
我认为在基本的解决方案中,你可以创建自己的小工具/小工具。这是它的一种开始-全功能-你可以根据你的目的更好地设计它。
library(shiny)
library(miniUI)
library(highcharter)
library(tidyverse)
hightchart_filter <- function(data) {
ui <- miniPage(
miniContentPanel(
# Dates ####
dateInput("date_start", "start_date", value = "1900-01-01", width = "25%"),
dateInput("date_end", "end_date", value = "2100-01-01", width = "25%"),
# Highchart ####
highchartOutput("high_plot", height = "500px")
)
)
server <- function(input, output, session) {
# update for data boxes
updateDateInput(session, "date_start", value = data$date %>% min())
updateDateInput(session, "date_end", value = data$date %>% max())
# filter data
data_filtered <- reactive({
data %>% filter(between(date, input$date_start, input$date_end))
})
# Highchart ####
output$high_plot <- renderHighchart({
hchart(data_filtered(), "line", hcaes(x = "date", y = "value01", group = "variable"))
})
}
runGadget(ui, server)
}并运行它:
hightchart_filter(economics_long)https://stackoverflow.com/questions/52822258
复制相似问题