我在远程aws服务器(ubuntu)上安装了RStudio服务器,并希望同时运行多个项目(其中一个项目需要很长时间才能完成)。在Windows上有一个简单的GUI解决方案,如“在新窗口中打开项目”。 rstudio服务器有类似的东西吗?
简单的问题,但没有找到解决方案,除了这与Mac相关的question,提供
使用项目运行多个rstudio会话
但是如何?
答案 0 :(得分:13)
虽然运行批处理脚本当然是一个不错的选择,但它并不是唯一的解决方案。有时您可能仍希望在不同的会话中进行交互式使用,而不必像批处理脚本那样执行所有操作。
没有什么能阻止您在不同端口上的Ubuntu服务器上运行多个RStudio服务器实例。 (我发现通过docker as outlined here启动RStudio非常容易。因为即使关闭浏览器窗口,实例也会继续运行,你可以轻松启动多个实例并在它们之间切换。你只需要切换时再次登录。
不幸的是,RStudio-server仍然会阻止您同时在浏览器中打开多个实例(请参阅help forum)。这不是一个大问题,因为您只需要再次登录,但您可以使用不同的浏览器来解决它。
编辑:多个实例都可以,只要它们不在同一个浏览器上,同一个浏览器用户和同一个IP地址上。例如关于127.0.0.1的会话和另一个关于0.0.0.0的会话就没问题。更重要的是,即使它们不是“开放”的,实例也会继续运行,所以这确实不是问题。唯一需要注意的是,您必须重新登录才能访问该实例。
对于项目,您将看到可以使用右上角的“项目”按钮在项目之间切换,但是这将保留您的其他会话,我认为它实际上不支持同时执行代码。您需要运行R环境的多个实例才能实际执行此操作。
答案 1 :(得分:3)
通常你不需要Rstudio的几个实例 - 在这种情况下只需将代码保存在.R文件中并使用ubuntu命令提示符启动它(可能使用屏幕)
Rscript script.R
这将启动一个单独的R会话,它将在不冻结Rstudio的情况下完成工作。您也可以传递参数,例如
# script.R -
args <- commandArgs(trailingOnly = TRUE)
if (length(args) == 0) {
start = '2015-08-01'
} else {
start = args[1]
}
console -
Rscript script.R 2015-11-01
答案 2 :(得分:2)
我认为您需要R Studio Server Pro才能使用多个用户/会话登录。
您可以在下面看到比较表以供参考。
答案 3 :(得分:0)
我通过在Singularity实例中隔离多个RStudio服务器来运行它们。使用命令singularity pull shub://nickjer/singularity-rstudio
我使用两个脚本:
run-rserver.sh
:
#!/bin/env bash
set -ue
thisdir="$(dirname "${BASH_SOURCE[0]}")"
# Return 0 if the port $1 is free, else return 1
is_port_free(){
port="$1"
set +e
netstat -an |
grep --color=none "^tcp.*LISTEN\s*$" | \
awk '{gsub("^.*:","",$4);print $4}' | \
grep -q "^$port\$"
r="$?"
set -e
if [ "$r" = 0 ]; then return 1; else return 0; fi
}
# Find a free port
find_free_port(){
local lower_port="$1"
local upper_port="$2"
for ((port=lower_port; port <= upper_port; port++)); do
if is_port_free "$port"; then r=free; else r=used; fi
if [ "$r" = "used" -a "$port" = "$upper_port" ]; then
echo "Ports $lower_port to $upper_port are all in use" >&2
exit 1
fi
if [ "$r" = "free" ]; then break; fi
done
echo $port
}
port=$(find_free_port 8080 8200)
echo "Access RStudio Server on http://localhost:$port" >&2
"$thisdir/cexec" \
rserver \
--www-address 127.0.0.1 \
--www-port $port
cexec
:
singularity instance
机制可避免PID 1使用派生的R会话,并在rserver关闭后继续存在。相反,它们成为奇点实例的子代,并在它们关闭时被杀死。 /data
并将其设置为主文件夹(如果您不关心每台计算机上可重复的路径,则此步骤可能不是必需的)#!/usr/bin/env bash
# Execute a command in the container
set -ue
if [ "${1-}" = "--help" ]; then
echo <<EOF
Usage: cexec command [args...]
Execute `command` in the container. This script starts the Singularity
container and executes the given command therein. The project root is mapped
to the folder `/data` inside the container. Moreover, a temporary directory
is provided at `/tmp` that is removed after the end of the script.
EOF
exit 0
fi
thisdir="$(dirname "${BASH_SOURCE[0]}")"
container="rserver_200403.sif"
# Create a temporary directory
tmpdir="$(mktemp -d -t cexec-XXXXXXXX)"
# We delete this directory afterwards, so its important that $tmpdir
# really has the path to an empty, temporary dir, and nothing else!
# (for example empty string or home dir)
if [[ ! "$tmpdir" || ! -d "$tmpdir" ]]; then
echo "Error: Could not create temp dir $tmpdir"
exit 1
fi
# check if temp dir is empty (this might be superfluous, see
# https://codereview.stackexchange.com/questions/238439)
tmpcontent="$(ls -A "$tmpdir")"
if [ ! -z "$tmpcontent" ]; then
echo "Error: Temp dir '$tmpdir' is not empty"
exit 1
fi
# Start Singularity instance
instancename="$(basename "$tmpdir")"
# Maybe also superfluous (like above)
rundir="$(readlink -f "$thisdir/.run/$instancename")"
if [ -e "$rundir" ]; then
echo "Error: Runtime directory '$rundir' exists already!" >&2
exit 1
fi
mkdir -p "$rundir"
singularity instance start \
--contain \
-W "$tmpdir" \
-H "$thisdir:/data" \
-B "$rundir:/data/.rstudio" \
-B "$thisdir/.rstudio/monitored/user-settings:/data/.rstudio/monitored/user-settings" \
"$container" \
"$instancename"
# Delete the temporary directory after the end of the script
trap "singularity instance stop '$instancename'; rm -rf '$tmpdir'; rm -rf '$rundir'" EXIT
singularity exec \
--pwd "/data" \
"instance://$instancename" \
"$@"