Error in grobToDev.default(gTree, dev)

半城伤御伤魂 提交于 2019-12-10 10:16:41

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!