[英]Error when importing ggplot bubble chart into Shiny
I am having some trouble with Shiny and ggplot 我在Shiny和ggplot上遇到了一些麻烦
When I run the following code to produce a bubble chart in Shiny I am getting this error message : 当我运行以下代码以在Shiny中生成气泡图时,出现此错误消息:
"Error in $<-.data.frame
( *tmp*
, "value", value = numeric(0)) : replacement has 0 rows, data has 3" “
$<-.data.frame
( *tmp*
,“ value”,value = numeric(0))中的错误:替换有0行,数据有3行”
But when I run it outside it is fine 但是当我在外面运行它很好
Any idea? 任何想法?
Thanks 谢谢
library(shiny)
library(ggplot2)
gtest = data.frame(cbind(sort(rep(c(1:3),5)),rep(c(1:5),3),sample(-8:8, 15)/10))
# Define a server for the Shiny app
server <- function(input, output) {
g3 <- reactive({
g2 <- gtest[gtest[2]==input$article,]
g2 <-g2[order(g2[3],decreasing = TRUE), ]
g2 <- rbind(g2[g2[1]==input$article,], g2[!g2[1]==input$article,])
angl <-seq(0, 360, length.out =(nrow(g2)))
angl <-angl[1:(length(angl)-1)]
g2[3] <-(max(g2[3])-min(g2[3]))*.3+(max(g2[3])-g2[3])
x<-c(0,g2[2:nrow(g2),3]*cos(angl%*%(pi/180)))
y<-c(0,g2[2:nrow(g2),3]*round(sin((pi/180)*angl),2))
g2<-cbind(g2,x,y)
colnames(g2) <- c("col1","col2","value","x","y")
g2
})
# Fill in the spot we created for a plot
output$g3plot = renderPlot({
p<-ggplot(g3(),aes(x,y,label= col1))+
geom_point(colour="white", fill="red", shape=21, size = 20)+
geom_text(size=5)+
theme_bw()
print(p)
})
}
#runApp("R/Test_shiny")
# Define the overall UI
ui <- fluidPage(
titlePanel("Articles by similarities"),
sidebarLayout(
sidebarPanel(
selectInput("article", "Article:", choice=unique(gtest[2]))), hr()),
mainPanel(
plotOutput("g3plot")
)
)
shinyApp(ui = ui, server = server)
Code seems to run from my side: 代码似乎在我这边运行:
I thus modified the following row: 因此,我修改了以下行:
x<-c(0,g2[2:nrow(g2),3]*cos(angl*(pi/180)))
Regards 问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.