r - 如何用nix创建一个可以启动Rstudio的环境

标签 r rstudio nix nix-flake

{
  description = "virtual environment with Rstudio, R, Shiny";
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";

  outputs = { self, nixpkgs, flake-utils }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = nixpkgs.legacyPackages.${system};

        rWrapper=pkgs.rWrapper;
        rstudioWrapper=pkgs.rstudioWrapper;
        rstudioServerWrapper=pkgs.rstudioServerWrapper;
        Rpackages=with pkgs.rPackages;[shiny];

        RwithPackages=   rWrapper.override{ packages =  Rpackages;};
        RStudio-with-my-packages = rstudioWrapper.override{ packages = Rpackages; };


        myDevTools = [
          #qtbase #patch
          RwithPackages
          RStudio-with-my-packages
        ];
      in {
        devShells.default = pkgs.mkShell {
          buildInputs = myDevTools;
        };
      });
}

这个 flake.nix 可以工作。

nix develop 

创建虚拟环境

但我尝试使用 rstudio,收到此错误:

 rstudio 

TTY detected. Printing informational message about logging configuration. Logging configuration loaded from '/etc/rstudio/logging.conf'. Logging to ''. qt.qpa.xcb: could not connect to display qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found. This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, xcb.

Aborted

我读过这篇文章webpage 。我在虚拟环境中输入此命令:

 export QT_QPA_PLATFORM=offscreen


 rstudio

TTY detected. Printing informational message about logging configuration. Logging configuration loaded from '/etc/rstudio/logging.conf'. Logging to ''. QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '/tmp/nix-shell.aeqLGO/runtime-pierre' Fontconfig error: Cannot load default config file: No such file: (null) Fontconfig error: No writable cache directories Fontconfig error: No writable cache directories Fontconfig error: No writable cache directories Fontconfig error: No writable cache directories WebEngineContext used before QtWebEngine::initialize() or OpenGL context creation failed. This plugin does not support propagateSizeHints() This plugin does not support raise() Failed to create OpenGL context for format QSurfaceFormat(version 2.0, options QFlagsQSurfaceFormat::FormatOption(), depthBufferSize 24, redBufferSize -1, greenBufferSize -1, blueBufferSize -1, alphaBufferSize -1, stencilBufferSize 8, samples 0, swapBehavior QSurfaceFormat::DefaultSwapBehavior, swapInterval 1, colorSpace QSurfaceFormat::DefaultColorSpace, profile QSurfaceFormat::NoProfile)

Aborted

最佳答案

我尝试在本地运行 Flake,它工作正常,但我没有任何自定义配置 - 我的系统以前从未运行过 RStudio,并且 /etc/rstudio 不存在。此错误可能是由 RStudio 在 /etc/rstudio 下加载非 Nix 托管配置引起的。

您的启动消息中包含以下内容:

Logging configuration loaded from '/etc/rstudio/logging.conf'

您可能使用来自另一个(非 Nix)RStudio 安装的一些插件进行本地配置,但在 nixdevelopment 环境中它们无法以某种方式加载(显然是一些 Qt 插件)。您可以尝试:

  • 删除或移动 /etc/rstudio 的内容以避免配置问题/冲突并检查其是否有效
  • 如果是,则启用之前移动的配置以将导致失败的配置一分为二

关于r - 如何用nix创建一个可以启动Rstudio的环境,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76539411/

相关文章:

r - 从 data.table 的一列进行组合,并从相应的列中求和

rstudio - 如何在 Windows 上将 Fira 代码安装到 R-Studio?

r - 使用 knit 和 Rstudio 自动调整 LaTeX 表格宽度以适合 pdf

nix - 如何在 nixos 上安装 systemd 服务

r - 如何使用 ddply 获取数据框中类的加权平均值?

r - 将数据转换为整数/nu 会更改数据

使用 for 循环引用 .SDcols 中的列

r - 编织到pdf时如何在方程中换行?

nix - 使用Nix打包CentOS5工具链依赖

nix - nixpkgs.fetchgit中的sha256是什么意思?值(value)从何而来?