在 Nix 中使用时 R Shiny 的 tmpdir 发生冲突/错误

问题描述 投票:0回答:1

问题:-

  • 在 Nix 系统中工作时,R 包的异常行为,特别是编码和重新加载包不起作用并产生错误。我需要重新启动 IDE 来评估我对代码所做的更改。

预期结果:-

  • 能够更改与 R 包交互的 R 代码,而无需每次进行更改时都重新启动 IDE。

详情:-

  • Nix 版本:- 24.05
  • R-shiny(相关的 r 包):- 1.8.0

我正在使用此处提供的

rPackages.Shiny
软件包https://github.com/NixOS/nixpkgs/blob/nixos-24.05/pkgs/development/r-modules/generic-builder.nix#L56。我自己就这样使用它,没有做任何改变。

这是我的配置的相关部分:-

      RStudio-with-my-packages = rstudioWrapper.override{
        packages = with rPackages; [ 
          ggplot2
          ggtree
          igraph
          ggpubr
          dplyr
          shiny
          tidyverse
          bigsnpr
          data_table
          bslib
          svglite
          ggExtra
          ape
          phylotools
          argparse
          rPackages.IRkernel
          rPackages.languageserver
          ];
      };

我正在尝试为我的雇主构建一个 Shiny 应用程序,并使用此处提供的 Shiny 教程中的示例代码:-

library(shiny)

# Define UI ----
ui <- page_fluid(
  titlePanel("Basic widgets"),
  layout_columns(
    col_width = 3,
    card(
      card_header("Buttons"),
      actionButton("action", "Action"),
      submitButton("Submit")
    ),
    card(
      card_header("Single checkbox"),
      checkboxInput("checkbox", "Choice A", value = TRUE)
    ),
    card(
      card_header("Checkbox group"),
      checkboxGroupInput(
        "checkGroup",
        "Select all that apply",
        choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3),
        selected = 1
      )
    ),
    card(
      card_header("Date input"),
      dateInput("date", "Select date", value = "2014-01-01")
    ),
    card(
      card_header("Date range input"),
      dateRangeInput("dates", "Select dates")
    ),
    card(
      card_header("File input"),
      fileInput("file", label = NULL)
    ),
    card(
      card_header("Help text"),
      helpText(
        "Note: help text isn't a true widget,",
        "but it provides an easy way to add text to",
        "accompany other widgets."
      )
    ),
    card(
      card_header("Numeric input"),
      numericInput("num", "Input number", value = 1)
    ),
    card(
      card_header("Radio buttons"),
      radioButtons(
        "radio",
        "Select option",
        choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3),
        selected = 1
      )
    ),
    card(
      card_header("Select box"),
      selectInput(
        "select",
        "Select option",
        choices = list("Choice 1" = 1, "Choice 2" = 2, "Choice 3" = 3),
        selected = 1
      )
    ),
    card(
      card_header("Sliders"),
      sliderInput(
        "slider1",
        "Set value",
        min = 0,
        max = 100,
        value = 50
      ),
      sliderInput(
        "slider2",
        "Set value range",
        min = 0,
        max = 100,
        value = c(25, 75)
      )
    ),
    card(
      card_header("Text input"),
      textInput("text", label = NULL, value = "Enter text...")
    )
  )
)

# Define server logic ----
server <- function(input, output) {

}

# Run the app ----
shinyApp(ui = ui, server = server)

代码第一次会产生工作输出,但每次我进行更改并重新加载应用程序时,都会收到以下错误:-

Warning in file.copy(script, dirname(outfile), overwrite = TRUE) :
  problem copying /nix/store/m81gr51dvwn9bd2b6w5gzy0qsnm36cwv-r-shiny-1.8.0/library/shiny/www/shared/selectize//js/selectize.min.js to /tmp/RtmpHhtDgJ/selectize6266c6e8c47f24e0f16990664c14d764/selectize.min.js: Permission denied
Warning in file.copy(script, dirname(outfile), overwrite = TRUE) :
  problem copying /nix/store/m81gr51dvwn9bd2b6w5gzy0qsnm36cwv-r-shiny-1.8.0/library/shiny/www/shared/selectize//accessibility/js/selectize-plugin-a11y.min.js to /tmp/RtmpHhtDgJ/selectize6266c6e8c47f24e0f16990664c14d764/selectize-plugin-a11y.min.js: Permission denied
Warning: Error in bslib::bs_dependency: Failed to copy the following script(s): /nix/store/m81gr51dvwn9bd2b6w5gzy0qsnm36cwv-r-shiny-1.8.0/library/shiny/www/shared/selectize//js/selectize.min.js, /nix/store/m81gr51dvwn9bd2b6w5gzy0qsnm36cwv-r-shiny-1.8.0/library/shiny/www/shared/selectize//accessibility/js/selectize-plugin-a11y.min.js.

Make sure script are absolute path(s).

我最好的猜测是,我被困在 Nix 和 R 之间,彼此不能很好地配合 - 但我无法弄清楚如何解决它,或者它可以在不使用包的底层 Nix 配置的情况下解决它(不确定这是否是 rPackage.Shiny 代码的行话)。

我可以做什么来调试这个问题?

r shiny nix
1个回答
0
投票

由detroyejr在这里回答https://discourse.nixos.org/t/unable-to-ergonomically-re-load-r-code-in-nix/55923/2?u=rijanhastwoears7

为方便起见引用答案:

如果您将该 bootstrap.min.css 文件复制到同一位置,您会收到相同的权限错误。 #成功

>cp /nix/store/3fxl93ds7a9ad0b4s64dqhbcd2ay85ny-r-shiny-1.9.1/library/shiny/www/shared/selectize//js/selectize.min.js .

# 失败

>cp /nix/store/3fxl93ds7a9ad0b4s64dqhbcd2ay85ny-r-shiny-1.9.1/library/shiny/www/shared/selectize//js/selectize.min.js .
>cp: cannot create regular file './selectize.min.js': Permission denied

所以这只是你有时必须解决的问题之一。我认为这是设计使然,但我不能 100% 确定原因。解决方法是将主题设置为不在 nix 商店中的位置。该文件不会有与从 /nix 复制的文件相同的限制。

>library(shiny)
>library(bslib)
>options(shiny.autoreload = TRUE)
># Copy the compiled css theme to your project folder.
>file.copy(precompiled_css_path(theme = bs_theme()), "./bootstrap.min.css")
> \# Define UI ----
>ui <- bslib:::page_fluid(
>  theme = "bootstrap.min.css",
>  ...
>  ...
>)

不是最漂亮的,但有利于发展。

© www.soinside.com 2019 - 2024. All rights reserved.