我在Shiny和ggplot上遇到了一些麻烦
当我运行以下代码以在Shiny中生成气泡图时,我收到此错误消息:
&#34; $<-.data.frame
中的错误(*tmp*
,&#34;值&#34;,值=数字(0)):
替换有0行,数据有3&#34;
但是当我在外面跑它时很好
有什么想法吗?
由于
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)
答案 0 :(得分:1)
代码似乎从我这边跑:
我因此修改了以下行:
x<-c(0,g2[2:nrow(g2),3]*cos(angl*(pi/180)))
此致