Issue:-
Expected outcome:-
Details:-
I am using the rPackages.Shiny
package available here https://github.com/NixOS/nixpkgs/blob/nixos-24.05/pkgs/development/r-modules/generic-builder.nix#L56 . I am using it as it without any changes of my own.
Here is what my the relevant section of my config looks like:-
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
];
};
I am trying to build a Shiny App for my employer and playing with sample code from the Shiny tutorial available here:-
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)
The code produces a working output the first time around but everytime I make a change and reaload the app, I get the following error:-
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).
My best guess is that I am stuck somewhere between Nix and R not meshing well with each other - but I am not being able to figure out how to solve it or it it can be solved without working with the underlying Nix config for the package (not sure if that is the jargon for the rPackage.Shiny code).
What can I do to debug this issue?
Answered by detroyejr here https://discourse.nixos.org/t/unable-to-ergonomically-re-load-r-code-in-nix/55923/2?u=rijanhastwoears7
Answer quoted for convenience:
If you cp that bootstrap.min.css file to the same location you get that same permissions error. #succeeds
>cp /nix/store/3fxl93ds7a9ad0b4s64dqhbcd2ay85ny-r-shiny-1.9.1/library/shiny/www/shared/selectize//js/selectize.min.js .
# Fails
>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
So this is just one of those nix things you have to work around sometimes. I presume this is by design, but I’m not 100% sure the reason. The fix is to set the theme to a location that’s not in the nix store. That file won’t have the same restrictions as what’s being copied from /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",
> ...
> ...
>)
Not the prettiest, but works for development.