问题
I am trying to build a app with shiny+gridSVG. This problem happened constantly and I have no idea about it.
My server.R:
library(grid)
library(lattice)
library(gridSVG)
shinyServer(function(input, output) {
data = reactive({
inFile = input$file1
if (is.null(inFile))
return(NULL)
read.csv(inFile$datapath, header=input$header,
sep=input$sep, quote=input$quote)
})
featurelist = reactive({
return (colnames(data()))
})
output$classUI = renderUI({
selectInput("classlabel","Classify by:", featurelist())
})
output$svg.grid = reactive({
dat = data()
features = featurelist()
#group = dat[,c(which(features == input$classlabel))]
subsetted.features = features[-c(which(features == input$classlabel))]
#classlabel.level = levels(group)
xyplot.out = xyplot(subsetted.features[1] ~ subsetted.features[2]|input$classlabel,
data = dat
)
tempsvg <- tempfile(fileext=".svg")
on.exit(unlink(tempsvg))
gridToSVG(name=tempsvg)
svgoutput <- readLines(tempsvg, n=-1)
svgoutput
})
})
this is my js:
<script>
var networkOutputBinding = new Shiny.OutputBinding();
$.extend(networkOutputBinding, {
find: function(scope) {
return $(scope).find('.shiny-network-output');
},
renderValue: function(el, data) {
$(el).html(data.join(''));
}
});
Shiny.outputBindings.register(networkOutputBinding, 'timelyportfolio.networkbinding');
</script>
And the error message in the console is:
Error in grobToDev.default(gTree, dev) : We shouldn't be here!
Do any one know the reason?
回答1:
I can't help with the reason why, but I had the same Error message and solved it by doing the following:
- Quitting RStudio.
- Updating to the latest version of R (in my case this was 3.2)
- Re-starting RStudio
- Re-installing the gridSVG package
The problem went away.
BTW: here is a neat way of re-installing your packages: http://www.r-bloggers.com/automated-re-install-of-packages-for-r-3-0/
回答2:
I'm hitting this problem too (not with shiny; I'm just trying to export a plot to SVG), and I'm not sure why—but for me it only happens when I call grid.export
within my script. If I re-display my plot and call it again interactively, it runs fine. I guess there's some sort of environmental difference playing into it?
来源:https://stackoverflow.com/questions/17255207/error-in-grobtodev-defaultgtree-dev