carpentries / workbench

Repository for Discussions and Materials about The Carpentries Workbench
https://carpentries.github.io/workbench/
Creative Commons Attribution 4.0 International
17 stars 7 forks source link

Include instructions to set up with conda #50

Closed twrightsman closed 10 months ago

twrightsman commented 1 year ago

I don't use RStudio and have been building Workbench lessons from the command line. For isolation from the rest of my system packages I looked in to installing everything with Conda on Linux, since I couldn't find this in the documentation.

Creating the environment

conda create -n workbench 'git>=2.28' 'r-base>=3.6' 'pandoc>=2.11' pkg-config libxslt python
conda activate workbench
R -e 'install.packages(c("sandpaper", "varnish", "pegboard", "tinkr"), repos = list(carpentries="https://carpentries.r-universe.dev/", CRAN="https://cran.us.r-project.org"))'

Note: python is only for using http.server to serve the web pages locally later; if someone knows the magical incantation to serve HTTP from R then python won't be needed in the environment.

Building the repository

R -e 'library(sandpaper); sandpaper::build_lesson(preview = FALSE)'

preview = FALSE is needed when building on a headless server without a GUI/browser.

Serving the lesson

python3 -m http.server -b $HOST -d site/docs $PORT`

I couldn't use sandpaper::serve() because I needed to bind to a specific IP and port, which sandpaper::serve() currently doesn't (seem to) support.

zkamvar commented 1 year ago

Thank you for opening this issue!

I have never isolated an R envionment using conda before so this is helpful!

WRT to the http server, the sandpaper::serve() function uses the {servr} package to host the server and it's options can be set up using the servr::server_config() function. Once you set those up, you can run sandpaper::serve():

# 127.0.0.1 and port 4321 are the defaults for servr
R -e 'servr::server_config(host = "127.0.0.1", port = "4321"); sandpaper::serve()'

from there you can preview the lesson at http://127.0.0.1:4321

I admit that I never actually had a good grasp on how to deploy it with a server from the command line; my setup is vim with Nvim-R.

twrightsman commented 1 year ago

Thanks @zkamvar! That is exactly what I was missing. I also updated my comment above to include the very important conda activate workbench step :smile:

zkamvar commented 1 year ago

Wunderbar! So, if I'm correct, then the setup for conda is:

Installation

conda create -n workbench 'git>=2.28' 'r-base>=3.6' 'pandoc>=2.11' pkg-config libxslt
conda activate workbench
R -e 'install.packages(c("sandpaper", "varnish", "pegboard", "tinkr"), \
  repos = list(carpentries="https://carpentries.r-universe.dev/", CRAN="https://cran.us.r-project.org"))'

Build and Preview

# 127.0.0.1 and port 4321 are the defaults for servr
R -e 'servr::server_config(host = "127.0.0.1", port = "4321"); sandpaper::serve()'
twrightsman commented 1 year ago

Does sandpaper::serve() try to open a browser window by default? That would be the only thing I'd add, otherwise looks good!

The docs do warn about this, but on Linux this will need to compile a lot of things which took a fair bit of time.

zkamvar commented 1 year ago

Does sandpaper::serve() try to open a browser window by default? That would be the only thing I'd add, otherwise looks good!

In an interactive session, it does launch a window, but because R -e is not launched interactively, you have to manually open it, or you can insert browseURL(servr::server_config()$url) in between the two R statements so that it launches before serving.

The docs do warn about this, but on Linux this will need to compile a lot of things which took a fair bit of time.

Ah yes, if you are on a major linux platform (Ubuntu, CentOS, etc), you should be able to use the Posit Package Manager to get binaries: https://packagemanager.rstudio.com/client/#/

Otherwise, yes, we have inadvertently inverted the pain threshold for getting things installed so that now linux users have the most difficult time and Windows and Mac users are largely plug-and-play. The only consolance I have is that the long installation time is going to be a rare occurance.

twrightsman commented 1 year ago

Unfortunately the server_config snippet above doesn't seem to work for me. For example, if we try R -e 'servr::server_config(host = "192.168.1.10", port = "5000"); sandpaper::serve()' it will still serve on 127.0.0.1 and port 4321.

zkamvar commented 1 year ago

Unfortunately the server_config snippet above doesn't seem to work for me. For example, if we try R -e 'servr::server_config(host = "192.168.1.10", port = "5000"); sandpaper::serve()' it will still serve on 127.0.0.1 and port 4321.

😩 that's what I get for testing with just the default config. I will add an ellipses to the serve function in the next release so that you should be able to run sandaper::serve(host = "192.168.1.10", port = "5000")

For reference, this is the documentation of those options that will be available:

https://yihui.r-universe.dev/servr/doc/manual.html#server_config

zkamvar commented 1 year ago

I've added the feature and pushed it to the universe. It should be available within the hour.

twrightsman commented 1 year ago

Thanks so much @zkamvar! I can confirm this works on my end.

twrightsman commented 10 months ago

It seems https://cran.us.r-project.org is not accessible (permanently?), so I had to update the R install command:

R -e 'install.packages(c("sandpaper", "varnish", "pegboard", "tinkr"), \
  repos = list(carpentries="https://carpentries.r-universe.dev/", CRAN="https://cloud.r-project.org"))'
zkamvar commented 10 months ago

Ah yes, sorry about that. CRAN is not yet an option because we need to ship quickly and the process for CRAN submission can get bogged down in very minor details.

I'm going to add this to the installation page so that I can close this issue. Sorry for the delay!

zkamvar commented 10 months ago

I just realised I misread your comment! Yes, "https://cloud.r-project.org" is likely going to return the best results as it will redirect your to the closest, most up-to-date server: https://cran.r-project.org/mirrors.html