我正在尝试使用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)
答案 0 :(得分:0)
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)
尝试这个。