R interactive plots over SSH often freeze

Viewed 204

Main question

I do a lot of interactive work in R using SSH and tmux. I connect using the -Y flag, e.g.

ssh -Y user@server

Then, I typically start a new tmux session:

tmux new -s name

When I first connect, my plots work fine. However, my connection often gets interrupted or I might disconnect for lunch. For this case, I have a line in my .bashrc that saves my current display:

if [ ! -f ~/.my.display ]; then
    touch ~/.my.display
fi

display=$(echo $DISPLAY)
if [[ $display != "" ]]; then
    echo "export DISPLAY="$DISPLAY > ~/.my.display
fi
source ~/.my.display

After disconnecting, when I tmux into my interactive R session, I typically need to reset my X11 window:

# reconnect to tmux session
ssh -Y user@server
tmux a -t name

# reset x11 window
graphics.off()
display = gsub(".*DISPLAY.", "", tail(readLines("~/.my.display"), n = 1))
x11(display, type = "Xlib")

This works most of the time. However, around 25% of the time, my graphics.off() call hangs for 30 minutes, which is incredibly frustrating. I often need to kill my session, losing all of my work.

Is there a way to call graphics.off() without it hanging for so long? Ideally, it would try this command for like 10 seconds, then throw an error if there is a problem.


Bonus

Within tmux, I often connect to other user accounts using SSH -Y. Therefore, the sequence of commands is:

# connect laptop -> user1
ssh -Y user1@server1
tmux a -t name

# connect user1 -> user2
ssh -Y user2@server2

I am having trouble making interactive plots with user2's account. Right now, my solution is to save user2's DISPLAY variable to their .my.display. Before plotting with user2 through tmux, I first SSH directly into user2's account, which properly properly configures their .my.display file. Then, I follow the same steps as before: graphics.off() and starting a new x11 window.

This seems unnecessarily complicated, so my second question is if there is a cleaner way to set this up?


I am using XQuartz 2.7.11 on Mac OS 10.12.6

0 Answers
Related