我正在尝试使用Shiny来创建googleVis气泡图。在Shiny服务器之外,这段代码工作正常:
df=data.frame(states=gun_stats$new_states, household=gun_stats$Gun.Ownership..2007., murder=gun_stats$Gun.Murder.Rate.per.100K..2010.,
attack_size=gun_stats$state_attacks,attack_size_group=gun_stats$attack_category,
gun_stats$x)
Bubble <- gvisBubbleChart(df, idvar="states", xvar="household", yvar="murder",colorvar="attack_size", sizevar="attack_size",
options=list(hAxis="{title:'% Housholds with Guns'}",
vAxis="{title: 'Gun muder rate per 100k'}",height="600"))
plot(Bubble)
然后我尝试按照以下方式将其放入Shiny应用程序中:
server.R
shinyServer(function(input, output, session) {
df=data.frame(states=gun_stats$new_states, household=gun_stats$Gun.Ownership..2007., murder=gun_stats$Gun.Murder.Rate.per.100K..2010.,
attack_size=gun_stats$state_attacks, attack_size_group=gun_stats$attack_category)
output$chart <- renderGvis({
gvisBubbleChart(df, idvar="states", xvar="household", yvar="murder",colorvar="attack_var", sizevar="attack_var",
options=list(hAxis="{title:'% Housholds with Guns'}",
vAxis="{title: 'Gun muder rate per 100k'}",height="600"))
})
})
ui.R
library(googleVis)
library(shiny)
pageWithSidebar(
headerPanel("Mass Shootings Overview"),
sidebarPanel(
selectInput("attack_var", "Choose a size metric",
choices = c("x", "attack_size"))
),
mainPanel(htmlOutput('chart'))
)
然而,这会返回:data.frame中的错误:参数意味着不同的行数:51,0
有什么建议吗?