-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add module - tab switch button * fix tab switch bug * update pr ci to monitor changes on .R files * update pr-ci * update pr-ci * change commit message * add echo msg if no changes to commit * Github Actions: style * add styler cache Co-authored-by: rrchai <[email protected]>
- Loading branch information
Showing
11 changed files
with
230 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
# Workflow derived from https://github.com/r-lib/actions/tree/master/examples | ||
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help | ||
on: | ||
issue_comment: | ||
types: [created] | ||
pull_request: | ||
branches: main | ||
paths: '**/*.R' | ||
|
||
name: Commands | ||
name: PR-CI | ||
|
||
jobs: | ||
# document: | ||
|
@@ -43,9 +44,8 @@ jobs: | |
# repo-token: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
style: | ||
if: ${{ github.event.issue.pull_request && (github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER') && startsWith(github.event.comment.body, '/style') }} | ||
name: style | ||
runs-on: ubuntu-latest | ||
name: styler | ||
runs-on: macOS-latest | ||
env: | ||
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} | ||
steps: | ||
|
@@ -60,6 +60,23 @@ jobs: | |
- name: Install dependencies | ||
run: Rscript -e 'install.packages("styler")' | ||
|
||
- name: save R.cache location | ||
id: save-r-cache-location | ||
run: | | ||
cat("##[set-output name=r-cache-location;]", R.cache::getCacheRootPath(), "\n", sep = "") | ||
shell: Rscript {0} | ||
|
||
- name: R.cache cache | ||
uses: actions/cache@v2 | ||
env: | ||
cache-name: r-cache | ||
with: | ||
path: ${{ r-cache-location }} | ||
key: ${{ runner.os }}-${{ env.cache-name }}-${{ github.sha }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ env.cache-name }}- | ||
${{ runner.os }}- | ||
- name: Style | ||
run: Rscript -e 'styler::style_pkg()' | ||
|
||
|
@@ -68,7 +85,7 @@ jobs: | |
git config --local user.name "$GITHUB_ACTOR" | ||
git config --local user.email "[email protected]" | ||
git add \*.R | ||
git commit -m 'Style' | ||
git commit -m 'Github Actions: style' || echo "No changes to commit" | ||
- uses: r-lib/actions/pr-push@v1 | ||
with: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#' Create switch button | ||
#' | ||
#' @param id The input variable to read value from | ||
#' @param .tab The \code{tabItem} object | ||
#' | ||
#' @importFrom magrittr %>% | ||
#' @export | ||
tabSwitchUI <- function(.tab, id = NULL) { | ||
if (is.null(id)) id <- "dca-tab-switch" | ||
ns <- NS(id) | ||
|
||
n_tabs <- length(.tab$children) | ||
|
||
tab_names <- getTabNames(.tab) | ||
var1 <- var2server(ns("tab-names"), tab_names) | ||
|
||
switch_btn_ids <- c(NS("prev", n_tabs)) | ||
|
||
.tab$children[[n_tabs]] <- .tab$children[[n_tabs]] %>% | ||
tagAppendChild( | ||
fluidRow( | ||
lapply(1:3, function(i) br()), | ||
column(1, offset = 1, arrowButton(ns(NS("prev", n_tabs)), "left")), | ||
lapply(1:3, function(i) br()) | ||
) | ||
) | ||
|
||
if (n_tabs > 1) { | ||
.tab$children[[1]] <- .tab$children[[1]] %>% | ||
tagAppendChild( | ||
fluidRow( | ||
lapply(1:3, function(i) br()), | ||
column(1, offset = 10, arrowButton(ns(NS("next", 1)), "right")), | ||
lapply(1:3, function(i) br()) | ||
) | ||
) | ||
switch_btn_ids <- c(switch_btn_ids, NS("next", 1)) | ||
} | ||
|
||
if (n_tabs > 2) { | ||
lapply(2:(n_tabs - 1), function(i) { | ||
.tab$children[[i]] <<- .tab$children[[i]] %>% | ||
tagAppendChild( | ||
fluidRow( | ||
lapply(1:3, function(i) br()), | ||
column(1, offset = 1, arrowButton(ns(NS("prev", i)), "left")), | ||
column(1, offset = 8, arrowButton(ns(NS("next", i)), "right")), | ||
lapply(1:3, function(i) br()), | ||
) | ||
) | ||
switch_btn_ids <<- c(switch_btn_ids, c(NS("prev", i), NS("next", i))) | ||
}) | ||
} | ||
|
||
var2 <- var2server(ns("switch-ids"), switch_btn_ids) | ||
|
||
return(tagList(.tab, var1, var2)) | ||
} | ||
|
||
#' Tab switch button server | ||
#' | ||
#' @param id The input id to read value from | ||
#' @param tab.id The id of \code{tabItem} object | ||
#' @param parent.session The session from parent scope | ||
#' @param parent.input The input from parent scope | ||
#' @param parent.output The output from parent scope | ||
#' | ||
#' @export | ||
#' | ||
tabSwitch <- function(id, tab.id, parent.session, parent.input, parent.output) { | ||
moduleServer( | ||
id, | ||
function(input, output, session) { | ||
lapply(isolate(input[["switch-ids"]]), function(name) { | ||
observeEvent(input[[name]], | ||
{ | ||
tab_names <- input[["tab-names"]] | ||
curr_inx <- which(tab_names == parent.input[[tab.id]]) | ||
# switch to next/previous tab based on which btn is clicked | ||
i <- ifelse(grepl("prev-[1-9+]", name), -1, 1) | ||
shinydashboard::updateTabItems(parent.session, | ||
tab.id, | ||
selected = tab_names[curr_inx + i] | ||
) | ||
}, | ||
ignoreNULL = TRUE, | ||
ignoreInit = FALSE | ||
) | ||
}) | ||
} | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.