so i'm trying to display an R generated image while using wxpython and rpy2...
The full 131 line code is here... https://gist.github.com/ACollectionOfAtoms/4286c0fc32838b03f2ea
So within the program, the user comes to a point where they are a window genereated by lst_view, which has two buttons "Ok" and "Visualize". Once Visualize is pressed this code is executed..
def graph(self,event):
f = open('results.csv', 'wb')
csvwriter = csv.writer(f)
for i in self.res:
for j in range(1,len(i)):
row = [i[0] ,str(i[j])]
csvwriter.writerow(row)
f.close()
r = robjects.r
r('''
source('vis.r')
''')
r_main = robjects.globalenv['main']
r_main()
return True
Where in vis.r we have:
graph <- function() {
res = read.csv("results.csv", header=FALSE)
res = mutate(res, Percent = 100*(V2/(sum(res$V2))))
ggplot(data=res, aes(x=V1, y=V2, fill=Percent)) + geom_bar(stat="identity") + coord_flip() + xlab('Facility') + ylab('Number Of Violations')
}
main <- function(){
print(graph())
}
This doesn't immediately generate the graph, instead it causes a new menu to appear and the graphic only displays if I go to "Page Setup"....
Anyone ideas?!