1

Am using ggplot to plot a pie chart as in the code below in RStudio and its working fine. the problem is when i want to use R shiny server.

indicatorTotals<-tapply(anc_data$Total,anc_data$Indicator,sum)
graphdatapie <- as.data.frame(indicatorTotals)
c <- ggplot(graphdatapie, aes(x=rownames(graphdatapie),y=indicatorTotals,fill = 
    indicatorTotals)) + geom_bar(width = 1,stat="identity")
print(c + coord_polar(theta = "y"))

the data is this format

                       indicatorTotals
ANC 1st visit                   248777
ANC 2nd visit                   231914
ANC 3rd visit                   162062
ANC 4th or more visits           99528

I get the following error message from the R shiny server ui.R.

Error:object 'graphdatapie' not found. 

What could be the problem???

Andrie
  • 176,377
  • 47
  • 447
  • 496
jonestats
  • 349
  • 1
  • 3
  • 10

1 Answers1

2

Add the following to the ggplot function: environment=environment() i.e

ggplot(graphdatapie, aes(x=rownames(graphdatapie),y=indicatorTotals,fill = 
             indicatorTotals), environment=environment()) 

Then restart the shiny-server. That will solve the problem.

Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149
Timothy Tuti
  • 992
  • 2
  • 15
  • 29
  • Thanks for adding the answer. However, @hadley already suggested a better approach than to add `environment=environment()`. Could you add his solution to your answer? – Paul Hiemstra May 21 '13 at 06:44