简体   繁体   中英

R tcltk2 progress bar error on virtual machines (AWS EC2 instance)

An R function I wrote is causing me problems when running it on an EC2 instance. It uses the tcltk2 package to create a progress bar to monitor the function progress. What works well on a desktop instance returns the following error on EC2:

Error in structure(.External(.C_dotTclObjv, objv), class = "tclObj") : 
  [tcl] invalid command name "toplevel".
In addition: Warning message:
In fun(libname, pkgname) : couldn't connect to display ":0"

I guess the problem is that EC2 has no "display" and therefore does not know how to handle the progress bar window popping up. I wonder if there is a way to fix this without disabling the progress bar altogether.

If you don't need to interact with anything on the display, but just let the application code show its progress bar, the simplest way would be to put a headless X server (probably Xvfb ) on the EC2 instance. That will allow the Tk package on the Tcl side to initialise itself, and in turn that will make things work on the R side of things.

Otherwise, if you are accessing the EC2 instance via ssh then you can use X forwarding to allow the progress bar to run on your local system. Obviously, for that to work you'll need to be running a local X server, which is easy enough on some platforms and really awkward on others, and a topic that must be answered better elsewhere. You might also be able to get this working with VNC or Remote Desktop , though I've much less experience with working with them.

If neither of those work, and the GUI part is really just a progress bar and other miscellaneous bits, you have to go in and edit the code to get rid of the GUI part. This is something you can work on locally. The first step is probably to disable the loading of the tcltk package (find library("tcltk") and remove it) and to then go through and fix (probably by strategic removal) all the parts that that breaks. Hopefully, that won't be too many! Also remember that you might be lucky and find that the code you're working with is just a GUI wrapper round something else and just sets up parameters and provides monitoring; for headless work, you can either have no monitoring or just print “ I'm not dead yet ” messages to the console.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM