简体   繁体   English

虚拟机(AWS EC2实例)上的R tcltk2进度栏错误

[英]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. 我编写的R函数在EC2实例上运行时导致我出现问题。 It uses the tcltk2 package to create a progress bar to monitor the function progress. 它使用tcltk2程序包创建进度条以监视功能进度。 What works well on a desktop instance returns the following error on EC2: 在桌面实例上运行良好的方法在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. 我猜问题是EC2没有“显示”,因此不知道如何处理弹出的进度条窗口。 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. 如果您不需要与显示器上的任何内容交互,而只需让应用程序代码显示其进度条,则最简单的方法是将无头X服务器(可能是Xvfb )放在EC2实例上。 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. 这将允许Tcl端的Tk包自身进行初始化,从而使事情在R端起作用。

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. 否则,如果要通过ssh访问EC2实例,则可以使用X转发来允许进度条在本地系统上运行。 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. 显然,要使其正常工作,您将需要运行本地X服务器,该服务器在某些平台上非常容易,而在其他平台上确实很尴尬,并且必须在其他地方更好地回答这个问题。 You might also be able to get this working with VNC or Remote Desktop , though I've much less experience with working with them. 您可能还可以使用VNC远程桌面 ,尽管我在使用它们方面的经验要少得多。

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. 如果这些都不起作用,并且GUI部分实际上只是一个进度条和其他杂项,则必须进入并编辑代码以摆脱GUI部分。 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. 第一步可能是禁用tcltk程序包的加载(查找library("tcltk")并删除它),然后遍历并修复(可能通过策略性删除)所有library("tcltk")的部分。 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; 还要记住,您可能很幸运,发现正在使用的代码只是一个GUI包装器,它只是对其他东西进行了设置,并设置了参数并提供了监视; for headless work, you can either have no monitoring or just print “ I'm not dead yet ” messages to the console. 对于无头的工作,您可以没有监视,也可以只在控制台上显示“ 我还没死 ”消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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