Skip to content

Commit

Permalink
CRAN release 0.4.9-1 (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
cb4ds authored Apr 1, 2020
1 parent 923e0b5 commit 67f2ed5
Show file tree
Hide file tree
Showing 36 changed files with 1,607 additions and 141 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: periscope
Type: Package
Title: Enterprise Streamlined 'Shiny' Application Framework
Version: 0.4.8
Version: 0.4.9-1
Authors@R: c(
person("Constance", "Brett", email="[email protected]", role = c("aut", "cre")),
person("Isaac", "Neuhaus", role = "aut", comment = "canvasXpress JavaScript Library Maintainer"),
Expand All @@ -12,7 +12,7 @@ Description: An enterprise-targeted scalable and UI-standardized 'shiny' framewo
including a variety of developer convenience functions with the goal of both
streamlining robust application development while assisting with creating a
consistent user experience regardless of application or developer.
URL: https://github.com/cb4ds/periscope.git, http://periscopeapps.org:3838, http://canvasxpress.org
URL: https://github.com/cb4ds/periscope.git, http://periscopeapps.org:3838, https://www.canvasxpress.org
BugReports: https://github.com/cb4ds/periscope/issues
Repository: BRAN
License: GPL-3
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by roxygen2: do not edit by hand

export(add_left_sidebar)
export(add_reset_button)
export(add_right_sidebar)
export(add_ui_body)
Expand Down
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
#Revisions and Change Log


### v0.4.9-1
* Fixed url typo in readme link


### v0.4.9
* Added functionality to remove the left sidebar
* Bugfixes for corner cases
* Updated tests, documentation


### v0.4.8
* Added functionality to add or remove the reset button from an existing application
* Added functionality to add the right sidebar to an existing application
Expand All @@ -16,6 +27,9 @@
* Bugfix - hide downloadable table button if there are no download functions defined
* Updated tests to be compatible with the next release of htmltools (0.4, schloerke)

### v0.4.5
* Bugfix - downloadable table button was not appearing when created in a reactive block

### v0.4.4
* Supporting openxlsx workbook format for xlsx downloads in addition to data tables
* Documentation updates
Expand Down
126 changes: 98 additions & 28 deletions R/convert_template.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Conversion functions for existing applications.


ui_filename <- "ui.R"
ui_plus_filename <- "ui_plus.R"
ui_right_sidebar_filename <- "ui_sidebar_right.R"
reset_button_expression <- "fw_create_sidebar\\(resetbutton = FALSE\\)"
no_reset_button_expression <- "fw_create_sidebar\\(\\)"
ui_filename <- "ui.R"
ui_no_sidebar_filename <- "ui_no_sidebar.R"
ui_plus_filename <- "ui_plus.R"
ui_plus_no_sidebar_filename <- "ui_plus_no_sidebar.R"
ui_left_sidebar_filename <- "ui_sidebar.R"
ui_right_sidebar_filename <- "ui_sidebar_right.R"
create_left_sidebar_expr <- "fw_create_sidebar\\("
create_left_sidebar_closed_expr <- "fw_create_sidebar\\(\\)"
no_reset_button_expr <- "fw_create_sidebar\\(resetbutton = FALSE"
no_reset_button_closed_expr <- "fw_create_sidebar\\(resetbutton = FALSE\\)"


# Checks if the location contains a periscope application.
Expand All @@ -17,6 +22,58 @@ no_reset_button_expression <- "fw_create_sidebar\\(\\)"
result
}

#' Add the left sidebar to an existing application.
#'
#' @param location path of the existing application.
#'
#' @export
add_left_sidebar <- function(location) {
tryCatch({
if (is.null(location) || location == "") {
warning("Add left sidebar conversion could not proceed, location cannot be empty!")
}
else if (!dir.exists(location)) {
warning("Add left sidebar conversion could not proceed, location=<", location, "> does not exist!")
}
else if (!.is_periscope_app(location)) {
warning("Add left sidebar conversion could not proceed, location=<", location, "> does not contain a valid periscope application!")
}
else {
usersep <- .Platform$file.sep

files_updated <- c()
ui_content <- readLines(con = paste(location, ui_filename, sep = usersep))
ui_content_formatted <- gsub(" ", "", ui_content)
# update ui if needed
if (any(grepl("showsidebar=FALSE", ui_content_formatted))) {
if (any(grepl("fw_create_right_sidebar", ui_content_formatted))) {
new_ui_content <- readLines(con = system.file("fw_templ", ui_plus_filename, package = "periscope"))
} else {
new_ui_content <- readLines(con = system.file("fw_templ", ui_filename, package = "periscope"))
}
if (any(grepl("resetbutton=FALSE", ui_content_formatted))) {
new_ui_content <- gsub(create_left_sidebar_closed_expr, no_reset_button_closed_expr, new_ui_content)
}
writeLines(new_ui_content, con = paste(location, ui_filename, sep = usersep))

# add left_sidebar file
writeLines(readLines(con = system.file("fw_templ", "p_blank", ui_left_sidebar_filename, package = "periscope")),
con = paste(location, "program", ui_left_sidebar_filename, sep = usersep))

files_updated <- c(files_updated, c(ui_filename, ui_left_sidebar_filename))
}
if (length(files_updated) > 0) {
message(paste("Add left sidebar conversion was successful. File(s) updated:", paste(files_updated, collapse = ", ")))
} else {
message("Left sidebar already available, no conversion needed")
}
}
},
warning = function(w) {
warning(w$message, call. = FALSE)
})
invisible(NULL)
}

#' Add the right sidebar to an existing application.
#'
Expand All @@ -39,17 +96,18 @@ add_right_sidebar <- function(location) {

files_updated <- c()
# replace ui by ui_plus (take car of resetbutton!)
ui_content <- readLines(con = paste(location, ui_filename, sep = usersep))
ui_content <- gsub(" ", "", readLines(con = paste(location, ui_filename, sep = usersep)))
# update ui if needed
if (!any(grepl("fw_create_right_sidebar", ui_content))) {
# check if resetbutton is disabled
reset_button <- TRUE
if (any(grepl(reset_button_expression, ui_content))) {
reset_button <- FALSE
if (any(grepl("resetbutton=FALSE", ui_content))) {
reset_button <- FALSE
}
new_ui_content <- readLines(con = system.file("fw_templ", ui_plus_filename, package = "periscope"))
if (!reset_button) {
new_ui_content <- gsub(no_reset_button_expression, reset_button_expression, new_ui_content)
if (!any(grepl("showsidebar=FALSE", ui_content))) {
new_ui_content <- readLines(con = system.file("fw_templ", ui_plus_filename, package = "periscope"))
if (!reset_button) {
new_ui_content <- gsub(create_left_sidebar_closed_expr, no_reset_button_closed_expr, new_ui_content)
}
}
writeLines(new_ui_content, con = paste(location, ui_filename, sep = usersep))

Expand Down Expand Up @@ -94,14 +152,18 @@ remove_reset_button <- function(location) {

files_updated <- c()
ui_content <- readLines(con = paste(location, ui_filename, sep = usersep))
ui_content_formatted <- gsub(" ", "", ui_content)
# update ui if needed
if (!any(grepl(reset_button_expression, ui_content))) {
writeLines(gsub(no_reset_button_expression, reset_button_expression, ui_content),
con = paste(location, ui_filename, sep = usersep))
files_updated <- c(files_updated, ui_filename)
}
if (length(files_updated) > 0) {
message(paste("Remove reset button conversion was successful. File(s) updated:", paste(files_updated, collapse = ",")))
if (!any(grepl("resetbutton=FALSE", ui_content_formatted))) {
if (any(grepl("showsidebar=FALSE", ui_content_formatted))) {
message("Left sidebar not available, reset button cannot be removed")
} else {
new_ui_content <- gsub(create_left_sidebar_expr, no_reset_button_expr, ui_content)
writeLines(new_ui_content,
con = paste(location, ui_filename, sep = usersep))
files_updated <- c(files_updated, ui_filename)
message(paste("Remove reset button conversion was successful. File(s) updated:", paste(files_updated, collapse = ",")))
}
} else {
message("Reset button already removed, no conversion needed")
}
Expand Down Expand Up @@ -133,17 +195,25 @@ add_reset_button <- function(location) {
usersep <- .Platform$file.sep

files_updated <- c()
ui_content <- readLines(con = paste(location, ui_filename, sep = usersep))
ui_content <- readLines(con = paste(location, ui_filename, sep = usersep))
ui_content_formatted <- gsub(" ", "", ui_content)
# update ui if needed
if (any(grepl(reset_button_expression, ui_content))) {
writeLines(gsub(reset_button_expression, no_reset_button_expression, ui_content),
con = paste(location, ui_filename, sep = usersep))
files_updated <- c(files_updated, ui_filename)
}
if (length(files_updated) > 0) {
message(paste("Add reset button conversion was successful. File(s) updated:", paste(files_updated, collapse = ",")))
if (any(grepl("resetbutton=FALSE", ui_content_formatted))) {
if (any(grepl("showsidebar=FALSE", ui_content_formatted))) {
message("Left sidebar is not available, please first run 'add_left_sidebar'")
} else {
new_ui_content <- gsub(no_reset_button_expr, create_left_sidebar_expr, ui_content)
writeLines(new_ui_content,
con = paste(location, ui_filename, sep = usersep))
files_updated <- c(files_updated, ui_filename)
message(paste("Add reset button conversion was successful. File(s) updated:", paste(files_updated, collapse = ",")))
}
} else {
message("Reset button already available, no conversion needed")
if (any(grepl("showsidebar=FALSE", ui_content_formatted))) {
message("Left sidebar is not available, please first run 'add_left_sidebar'")
} else {
message("Reset button already available, no conversion needed")
}
}
}
},
Expand Down
73 changes: 40 additions & 33 deletions R/fw_helpers_external.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,40 +64,47 @@ fw_create_header_plus <- function(sidebar_right_icon = shiny::isolate(.g_opts$si
}

# Framework UI Left Sidebar Creation
fw_create_sidebar <- function(resetbutton = shiny::isolate(.g_opts$reset_button)) {
basic <- shiny::isolate(.g_opts$side_basic)
adv <- shiny::isolate(.g_opts$side_advanced)

if (!is.null(adv) && length(adv) > 0 && resetbutton) {
adv[[length(adv) + 1]] <- .appResetButton("appResetId")
fw_create_sidebar <- function(showsidebar = shiny::isolate(.g_opts$show_left_sidebar), resetbutton = shiny::isolate(.g_opts$reset_button)) {
result <- NULL
if (showsidebar) {
basic <- shiny::isolate(.g_opts$side_basic)
adv <- shiny::isolate(.g_opts$side_advanced)

if (!is.null(adv) && length(adv) > 0 && resetbutton) {
adv[[length(adv) + 1]] <- .appResetButton("appResetId")
}
result <- shinydashboard::dashboardSidebar(
width = shiny::isolate(.g_opts$sidebar_size),
.header_injection(), #injected header elements
.right_sidebar_injection(),
if (!is.null(basic[[1]]) && !is.null(adv[[1]])) {
shiny::div(class = "tab-content",
shiny::tabsetPanel(
id = "Options",
selected = shiny::isolate(.g_opts$side_basic_label),
shiny::tabPanel(
shiny::isolate(.g_opts$side_basic_label),
basic),
shiny::tabPanel(
shiny::isolate(.g_opts$side_advanced_label),
adv)))
}
else if (!is.null(basic[[1]]) && is.null(adv[[1]])) {
shiny::div(class = "notab-content",
basic)
}
else if (is.null(basic[[1]]) && !is.null(adv[[1]])) {
shiny::div(class = "notab-content",
adv)
})
} else {
result <- shinydashboard::dashboardSidebar(width = 0,
collapsed = TRUE,
.header_injection(),
.right_sidebar_injection(),
.remove_sidebar_toggle())
}

return(
shinydashboard::dashboardSidebar(
width = shiny::isolate(.g_opts$sidebar_size),
.header_injection(), #injected header elements
.right_sidebar_injection(),
if (!is.null(basic[[1]]) && !is.null(adv[[1]])) {
shiny::div(class = "tab-content",
shiny::tabsetPanel(
id = "Options",
selected = shiny::isolate(.g_opts$side_basic_label),
shiny::tabPanel(
shiny::isolate(.g_opts$side_basic_label),
basic),
shiny::tabPanel(
shiny::isolate(.g_opts$side_advanced_label),
adv)))
}
else if (!is.null(basic[[1]]) && is.null(adv[[1]])) {
shiny::div(class = "notab-content",
basic)
}
else if (is.null(basic[[1]]) && !is.null(adv[[1]])) {
shiny::div(class = "notab-content",
adv)
}
) )
result
}

# Framework UI Right Sidebar Creation
Expand Down
6 changes: 6 additions & 0 deletions R/fw_helpers_internal.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
reset_wait = 5000, #milliseconds
show_userlog = TRUE,
body_elements = c(),
show_left_sidebar = TRUE,
side_basic = .g_sidebar_default_value,
side_basic_label = "Basic",
side_advanced = .g_sidebar_default_value,
Expand Down Expand Up @@ -64,6 +65,11 @@
}, 5000);"))
}

.remove_sidebar_toggle <- function() {
shiny::tags$script(shiny::HTML("$('[class~=\"sidebar-toggle\"]').remove();
$('[class~=\"logo\"]').css('background-color', '#3c8dbc');"))
}

# Returns the custom css as HTML
.framework_css <- function() {
return( shiny::HTML("
Expand Down
Loading

0 comments on commit 67f2ed5

Please sign in to comment.