Skip to content

Commit

Permalink
add new env
Browse files Browse the repository at this point in the history
  • Loading branch information
MeWu-IDM committed Oct 9, 2024
1 parent 046cb7a commit 41a471d
Show file tree
Hide file tree
Showing 18 changed files with 392 additions and 2,382 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"version": "3.12",
"installJupyterlab": true
},
"ghcr.io/devcontainers/features/anaconda:1": {},
"ghcr.io/rocker-org/devcontainer-features/quarto-cli:1": {}
},
"customizations": {
Expand All @@ -21,7 +22,7 @@
}
}
},
"postCreateCommand": "",
"postCreateCommand": "bash ./.devcontainer/postCreateCommand_r.sh",
"postStartCommand": "bash ./.devcontainer/postStartCommand.sh",
"portsAttributes": {
"8888": {
Expand Down
12 changes: 12 additions & 0 deletions .devcontainer/postCreateCommand_r.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

# Install ZeroMQ
sudo apt-get update -y
sudo apt-get install libzmq3-dev -y

# Setup bash to allow conda to run
conda init bash && conda install -y ipykernel

# Allow JupyterLab and IRkernel ro run R workbook
R -e "install.packages('IRkernel')"
R -e "IRkernel::installspec()"
6 changes: 3 additions & 3 deletions .devcontainer/postStartCommand.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# change the default working directory for RStudio
echo "session-default-working-dir=${CODESPACE_VSCODE_FOLDER}" | sudo tee -a /etc/rstudio/rsession.conf
echo "session-default-working-dir=/workspaces/quarto_demo/" | sudo tee -a /etc/rstudio/rsession.conf

# Start RStudio Server
echo "Start R studeio Server"
Expand All @@ -15,11 +15,11 @@ fi
sleep 5
echo "Setup Jupyter-lab"
# Start Jupyter Lab
jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root --NotebookApp.token='' > jupyter_lab.log 2>&1 &
nohup jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root --NotebookApp.token='' > jupyter_lab.log 2>&1 &
sleep 5
if ! pgrep -x "jupyter-lab" > /dev/null; then
echo "Jupyter Lab failed to start. Restarting..."
jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root --NotebookApp.token='' > jupyter_lab.log 2>&1 &
nohup jupyter lab --ip=0.0.0.0 --port=8888 --no-browser --allow-root --NotebookApp.token='' > jupyter_lab.log 2>&1 &
fi

echo "Dev environment startup completed!"
50 changes: 2 additions & 48 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,54 +28,7 @@ jobs:
- name: Run Quarto in Docker container
run: |
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace mewu/data_access:latest bash -c "
source /opt/venv/bin/activate
echo 'activated virtualenv.'
chmod +x /workspace/r/install_quarto_extensions.expect
/workspace/r/install_quarto_extensions.expect
quarto list extensions
echo 'Check Quarto status:'
quarto check
echo 'Check R script path:'
which Rscript
FOLDERS=(python r)
echo 'Folders to process: \${FOLDERS[@]}'
for FOLDER in \"\${FOLDERS[@]}\"; do
echo \"Searching for .qmd and .ipynb files in /workspace/\$FOLDER...\"
find \"/workspace/\$FOLDER\" \( -name '*.qmd' -o -name '*.ipynb' \) | while read -r file; do
echo \"Processing file: \$file\"
# Remove the /workspace prefix from the file path
relative_dir=\$(dirname \"\${file#'/workspace/'}\")
# Install extension to the folder directly
pushd \$relative_dir
/workspace/r/install_quarto_extensions.expect
popd
target_dir=\"/workspace/gallery/\$relative_dir\"
echo \"Creating target directory: \$target_dir\"
mkdir -p \"\$target_dir\" && echo \"Directory \$target_dir created.\"
echo \"Attempting to render \$file with execution...\"
if quarto render \"\$file\" --to html --output-dir \"\$target_dir\"; then
echo \"Successfully rendered \$file with execution.\"
else
echo \"Failed to render \$file with execution. Rendering without execution...\"
if quarto render \"\$file\" --to html --no-execute --output-dir \"\$target_dir\"; then
echo \"Successfully rendered \$file without execution.\"
else
echo \"Rendering failed for \$file, even without execution.\"
fi
fi
done
done"
docker run --rm -v ${{ github.workspace }}:/workspace -w /workspace mewu/data_access:latest bash -c "run_quarto_publish.sh"
- name: Generate Index HTML
run: |
Expand All @@ -101,6 +54,7 @@ jobs:
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
- name: Deploy to GitHub Pages
if: github.ref == 'refs/heads/main'
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
Expand Down
40 changes: 32 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ RUN apt-get update && apt-get install -y \
libharfbuzz-dev \
libfribidi-dev \
libfreetype6-dev \
libgl1-mesa-glx \
libegl1-mesa \
libxrandr2 \
libxss1 \
libxcursor1 \
libxcomposite1 \
libasound2 \
libxi6 \
libxtst6 \
gdebi-core \
software-properties-common \
ffmpeg \
Expand Down Expand Up @@ -56,24 +65,39 @@ RUN /opt/venv/bin/python -m ipykernel install --user --name=venv --display-name
RUN wget https://github.com/quarto-dev/quarto-cli/releases/download/v1.5.57/quarto-1.5.57-linux-amd64.deb
RUN dpkg -i quarto-1.5.57-linux-amd64.deb

# Expose ports for RStudio (8787) and Jupyter (8888)
# Install Anaconda
# Set environment variable for non-interactive Anaconda install
ENV PATH /opt/conda/bin:$PATH

# Download and install Anaconda
RUN wget --quiet https://repo.anaconda.com/archive/Anaconda3-2023.09-0-Linux-x86_64.sh -O ~/anaconda.sh && \
/bin/bash ~/anaconda.sh -b -p /opt/conda && \
rm ~/anaconda.sh && \
/opt/conda/bin/conda clean -i -t -p -y

# Update conda to the latest version
RUN conda update -n base -c defaults conda

# Set the default shell to bash and activate Conda environment
SHELL ["/bin/bash", "-c"]

# Ensure conda is activated on startup
RUN echo "source /opt/conda/etc/profile.d/conda.sh" >> ~/.bashrc

WORKDIR /app

COPY r /app/r
COPY python /app/python

# Install python packages in venv
RUN /opt/venv/bin/pip install -r python/requirements.txt

# Expose ports for RStudio (8787) and Jupyter (8888)
EXPOSE 8787
EXPOSE 8888

# Install renv globally for all users
# Install essentials globally for all users
RUN R -e "install.packages('renv', repos='https://cran.rstudio.com/')"

# Install R packages
RUN Rscript /app/r/install_packages.R
RUN R -e "install.packages('knitr', repos='https://cran.rstudio.com/')"
RUN R -e "install.packages('rmarkdown', repos='https://cran.rstudio.com/')"
RUN R -e ".libPaths()"

# Add /usr/local/bin to the PATH for all users
ENV PATH="/usr/local/bin:$PATH"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
205 changes: 205 additions & 0 deletions r/samples/shinylive_demo/shiny_demo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 7,
"id": "88b29033-79a1-40f1-a755-8f10e67f3442",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"Installing package into ‘/usr/local/lib/R/site-library’\n",
"(as ‘lib’ is unspecified)\n",
"\n",
"Installing package into ‘/usr/local/lib/R/site-library’\n",
"(as ‘lib’ is unspecified)\n",
"\n",
"Installing package into ‘/usr/local/lib/R/site-library’\n",
"(as ‘lib’ is unspecified)\n",
"\n",
"Installing package into ‘/usr/local/lib/R/site-library’\n",
"(as ‘lib’ is unspecified)\n",
"\n",
"Installing package into ‘/usr/local/lib/R/site-library’\n",
"(as ‘lib’ is unspecified)\n",
"\n",
"also installing the dependencies ‘colorspace’, ‘farver’, ‘labeling’, ‘munsell’, ‘RColorBrewer’, ‘viridisLite’, ‘gtable’, ‘isoband’, ‘scales’\n",
"\n",
"\n"
]
}
],
"source": [
"install.packages(\"shinylive\")\n",
"install.packages(\"shiny\")\n",
"install.packages(\"shinyWidgets\")\n",
"install.packages(\"dplyr\")\n",
"install.packages(\"ggplot2\")"
]
},
{
"cell_type": "markdown",
"id": "e03329ba-510e-4f00-bd20-6ada312e5d0d",
"metadata": {},
"source": [
"---\n",
"title: \"Template for r-shinylive Quarto document (Covid Example)\"\n",
"format:\n",
" html:\n",
" resources: \n",
" - shinylive-sw.js\n",
"filters:\n",
" - shinylive\n",
"---"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "09f6b537-b184-4ea6-b9b9-190f96207cdb",
"metadata": {},
"outputs": [],
"source": [
"options(timeout = 6000)\n",
"library(shiny)\n",
"library(dplyr)\n",
"library(ggplot2)\n",
"library(shinyWidgets)\n",
"\n",
"# Download real COVID data for Washington state counties from the New York Times GitHub repo\n",
"covid_url <- \"https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-counties.csv\"\n",
"covid_data <- read.csv(covid_url)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "0a03f7b5-18cf-4df3-98b7-657cd171731e",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\n",
"Listening on http://127.0.0.1:7477\n",
"\n"
]
}
],
"source": [
"\n",
"# Filter for Washington state and prepare the data\n",
"washington_covid_data <- covid_data %>%\n",
" filter(state == \"Washington\") %>%\n",
" select(date, county, cases) %>%\n",
" mutate(year_month = format(as.Date(date), \"%Y%m\")) # Create year_month column\n",
"\n",
"# Create a vector of unique year_month values from the dataset\n",
"valid_year_months <- sort(unique(washington_covid_data$year_month))\n",
"valid_year_months_index <- seq_along(valid_year_months)\n",
"\n",
"# Define the UI\n",
"ui <- fluidPage(\n",
" titlePanel(\"COVID Case Counts by Month-Year in Washington Counties\"),\n",
" \n",
" # Use fluidRow to place the slider at the top, spanning the entire page width\n",
" fluidRow(\n",
" column(12, # 12 columns to span full width\n",
" sliderTextInput(\"selected_year_month\", \n",
" \"Select Year and Month:\", \n",
" choices = valid_year_months, # Use year-month values directly\n",
" selected = \"202001\", # Start with the first year-month\n",
" animate = animationOptions(interval = 1000, loop = FALSE))\n",
" )\n",
" ),\n",
" \n",
" # Main panel for the plot below the slider\n",
" fluidRow(\n",
" column(12, # This will also span the entire width\n",
" plotOutput(\"histogramPlot\")\n",
" )\n",
" )\n",
")\n",
"\n",
"\n",
"# Define the server\n",
"server <- function(input, output) {\n",
" output$histogramPlot <- renderPlot({\n",
" filtered_data <- washington_covid_data %>%\n",
" filter(year_month == as.character(input$selected_year_month)) %>%\n",
" group_by(county) %>%\n",
" summarize(total_cases = max(cases, na.rm = TRUE)) # Get max case count for each county in the selected year_month\n",
" \n",
" ggplot(filtered_data, aes(x = county, y = total_cases)) +\n",
" geom_bar(stat = \"identity\", fill = \"steelblue\") +\n",
" labs(title = paste(\"COVID Cases in\", input$selected_year_month),\n",
" x = \"County\", \n",
" y = \"Total Case Count\") +\n",
" theme_minimal() +\n",
" theme(axis.text.x = element_text(angle = 45, hjust = 1))\n",
" })\n",
"}\n",
"\n",
"# Run the Shiny app\n",
"shinyApp(ui = ui, server = server)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "d050a599-2d6c-4338-9d6f-5ed08de7f98e",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"'/workspaces/quarto_demo/.devcontainer'"
],
"text/latex": [
"'/workspaces/quarto\\_demo/.devcontainer'"
],
"text/markdown": [
"'/workspaces/quarto_demo/.devcontainer'"
],
"text/plain": [
"[1] \"/workspaces/quarto_demo/.devcontainer\""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"getwd()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bf722ea2-9268-4a24-a275-4a3cf4c7c766",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "4.4.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
File renamed without changes.
Loading

0 comments on commit 41a471d

Please sign in to comment.