反应函数不适用于创建 Choropleth 地图

Reactive function is not working for creating Choropleth Map

我正在尝试使用闪亮的 googleVis 创建等值线图。当我创建根据输入选择特定数据的反应函数时,出现错误:

as.vector 中的错误:无法将类型 'closure' 强制转换为类型 'list'

的向量

使用的数据是原始数据集的样本。

谁能帮我解决这个问题?

df <- data.frame(GEO = c("Belgium", "Germany" , 
                         "France","Italy","Sweden","Slovakia" ),
                 PRODUCT = c("Total petroleum products","Gas"),
                 TIME = c(1990),
                 Value = c(18345, 126544, 88659,90069,14670,4974), 
                 stringsAsFactors = FALSE)


library(shiny)
library(shinydashboard)
library(googleVis)

ui <- fluidPage(titlePanel("Energy consumption in Europe"),

                dashboardPage(
                  dashboardHeader(),
                  dashboardSidebar(width = 240,
                                   br(),
                                   br(),
                                   br(),
                                   selectizeInput("Type",
                                                  label = em("Select Type", style="text-align:center;color:#FFA319;font-size:150%"),
                                                  choices = unique(df$PRODUCT),
                                                  selected = "")),
                  dashboardBody(htmlOutput("firstMap"))
                ))

server <- function(input, output) {

  data_selected<-reactive({
    df[df$PRODUCT%in%input$Type]
  })


  output$firstMap <- renderGvis({
    data(data_selected)
    map<-gvisGeoChart(data_selected,"GEO", "Value",
                      options=list(region="150"))


    return(map)
  })
}

shinyApp(ui, server)
server <- function(input, output) {

data_selected<-reactive({
df[df$PRODUCT%in%input$Type,]
 })


 output$firstMap <- renderGvis({
 req(data_selected())
 map<-gvisGeoChart(data_selected(),"GEO", "Value",
                  options=list(region="150"))


     return(map)
 })
}

shinyApp(ui, server)

试试这个。