不过,我能够使用下面的脚本创建一个交互式的geoChart,问题是区分地图颜色的比例每天都在变化。我的数据集是美国每个州一年的每日统计数据。
例如,对于第一天,刻度采用该特定日期的最小值和最大值。但我正在尝试更改脚本,以便在任何给定的一天(并显示全年的最小和最大值)都保持不变。
有人能告诉我怎么做吗?谢谢!
global.R
library(shiny)
states <- read.csv("queries_geo.csv")
states$StartDate <- as.Date(states$StartDate, "%m/%d/%Y")ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("PlayStation4 Search Volume Trend by States"),
sidebarLayout(
sidebarPanel(
sliderInput("StartDate", "Quarter",
min = min(states$StartDate),
max = max(states$StartDate),
value = min(states$StartDate),
step = 1,
animate = TRUE)),
mainPanel(
htmlOutput ("GeoStates")
))))server.R
library(shiny)
library(dplyr)
library(googleVis)
shinyServer(function(input,output,session){
querydate <- reactive({
states_new <- states %>%
filter(StartDate == input$StartDate) %>%
select(Geo,Queries) %>%
arrange(Geo)})
output$GeoStates <- renderGvis ({
GeoStates <- gvisGeoChart(querydate(),
"Geo", #locationvar
"Queries", # colorvar
options = list(region = "US",
displayMode = "regions",
resolution = "provinces",
sizeAxis.maxValue = max(states$Queries),
sizeAxis.minValue = min(states$Queries),
width = 600,
height = 400)
)})})发布于 2015-12-21 08:36:57
我想出了办法。我正在张贴我的解决方案,希望它能在未来节省其他人的时间!谢谢你阅读我的问题!
global.R =>在这部分没有变化
library(shiny)
states <- read.csv ("queries_geo.csv")
states$StartDate <- as.Date(states$StartDate, "%m/%d/%Y")ui.R =>在这部分发生了显著变化。这段代码不是在server.R和ui.R中创建一个地图图表,而是在ui.R中创建一个地图。这样,地图比例尺保持不变,动画工作平稳。R只是将反应性数据输入ui.R中的地图图表。
library(shiny)
library(googleVis)
library(googleCharts)
min_query <- min(states$Queries)
max_query <- max(states$Queries)
shinyUI(fluidPage(
# This line loads the Google Charts JS library
googleChartsInit(),
# https://developers.google.com/chart/interactive/docs/gallery/geochart
googleGeoChart("GeoStates",
width = 1000,
height = 600,
options = list(
fontSize = 13,
region = "US",
displayMode = "regions",
resolution = "provinces",
colorAxis = list(
maxValue = round(max_query, -3),
minValue = round(min_query, -1)
))),
fluidRow(
shiny::column(4, offset = 4,
sliderInput("StartDate",
"StartDate",
min = min(states$StartDate),
max = max(states$StartDate),
value = min(states$StartDate),
step = 60,
animate = TRUE)
))))server.R
library(shiny)
library(dplyr)
library(googleVis)
shinyServer(function(input,output,session){
querydate <- reactive({
states_new <- states %>%
filter(StartDate == input$StartDate) %>%
select(Geo,Queries) %>%
arrange(Geo)
})
output$GeoStates <- reactive({
list(
data = googleDataTable(querydate())
)})})https://stackoverflow.com/questions/34331331
复制相似问题