Skip to content

Commit

Permalink
57 UI updates (#72)
Browse files Browse the repository at this point in the history
* Add missing function for has_value. Closes #71
* Change save and close buttons in file upload
* Set max height to input and output options
* Update bootstrap table with CI range
* Updates to summary tab
* Add ability to export bootstrap table
* Add ui for export
* Bump version and add news
* Update names for exported files
  • Loading branch information
ohjakobsen authored Dec 20, 2023
1 parent 3fc1100 commit 2ec54fb
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 53 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
Package: pioneeR
Title: Perform productivity analyses in a web browser
Version: 0.2.0.9000
Version: 0.3.0
Authors@R: c(
person("Ove Haugland", "Jakobsen", role = c("aut", "cre"), email = "[email protected]"),
person("Jan Roar", "Beckstrøm", role = "ctb", email = "[email protected]"),
person("Lars Skaage", "Engebretsen", role = "ctb", email = "[email protected]"),
person("Jonas", "Månsson", role = "ctb", email = "[email protected]"),
person("Aleksander", "Eilertsen", role = "ctb", email = "[email protected]"),
person("Joachim", "Sandnes", role = "ctb", email = "[email protected]"),
person(family = "Riksrevisjonen", role = "cph"))
Description: What the package does (one paragraph).
License: GPL-3 | file LICENSE
Expand Down
6 changes: 4 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pioneeR 0.2.0.9000
# pioneeR 0.3.0

## Breaking changes:

Expand All @@ -17,13 +17,15 @@
- Layout changed to `layout_sidebar()` from the bslib package to improve UI and fix compatability with bslib >= 0.6.0 and Boostrap 5.3 (#44)
- Analysis report has been updated and simplified to make the results from the app easier to reproduce (#35)
- `runPioneeR()` has been renamed `run_pioneer()`. `runPioneeR()` will still work, but will be deprecated in a later version
- Simplified logic in PDF report generated from the analysis tab
- Improvements to the user interface and user experience (#57)
- For time series data, all columns are now available to select as year/time variable. If a column with values within the range \[1900, 2100\] exists, this column will automatically be selected (#41)

## Bug fixes

- If the user selects a port number that is considered unsafe, a random port number is selected instead (#40)
- Fixed a bug where an error occurred if any of the model parameters were not found in the column names (#39)
- Fixed a bug in the scale efficiency tab where numbers where rounded twice (#47)
- Fixed a bug that would block Excel-files from properly uploading (#71)

# pioneeR 0.2.0

Expand Down
3 changes: 2 additions & 1 deletion inst/app/R/fct_dea-boostrap.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ process_boot <- function(rts, orientation, h, alpha, theta, boot) {
bias = bias,
eff_bc = theta_tilde,
lower = as.vector(theta_ci[, 1]),
upper = as.vector(theta_ci[, 2])
upper = as.vector(theta_ci[, 2]),
range = apply(theta_ci, 1, diff)
)
)
invisible(out)
Expand Down
7 changes: 7 additions & 0 deletions inst/app/R/fct_file-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ check_file <- function(file) {
file

}

has_value <- function(x) {
if (length(x) > 1L) return(sapply(x, has_value, USE.NAMES = FALSE))
if (is.null(x) || is.na(x)) return(FALSE)
if (!is.character(x)) x <- as.character(x)
nzchar(x)
}
4 changes: 2 additions & 2 deletions inst/app/R/mod_file-upload.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ file_upload_srv <- function(id) {
easyClose = TRUE, size = 'xl',
title = 'Upload file',
footer = tagList(
actionButton(ns('file_save'), 'Save'),
bs_modal_button('Close')
actionButton(ns('file_save'), 'Save and close', class = 'btn-sm btn-primary', `data-bs-dismiss` = 'modal'),
bs_modal_button('Cancel', size = 'sm', color = 'secondary')
),
div(
class = 'input-group mb-3',
Expand Down
138 changes: 100 additions & 38 deletions inst/app/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,11 @@ shinyServer(function(input, output, session) {
card_header('Select data'),
card_body(
'Upload a file to get started by pressing the Upload file button in the vertical
menu to the left. Accepted file types are Excel, Stata, R data.frames stored as
RDS-files, comma-, semicolon- og tabseparated files (.tsv, .csv or .txt). When you
upload a file, you get a preview of the contents. You can adjust the file import
settings if needed. Remember to save the file to the current session.'
menu to the left. Accepted file types are Excel, Stata (version 14 or newer), R
data.frames stored as DS-files, comma-, semicolon- og tabseparated files (.tsv,
.csv or .txt). When you upload a file, you get a preview of the contents. You can
adjust the file import settings if needed. Remember to save the file to the current
session.'
))
} else {
# Check for list wise deletion and inform the user if observations have been removed
Expand Down Expand Up @@ -364,7 +365,9 @@ shinyServer(function(input, output, session) {

output$dea.plot.save <- downloadHandler(
filename = function() {
sprintf('dea-plot-%s.%s', Sys.Date(), input$dea_dl_format)
sprintf(
'dea-plot-%s-%s.%s', model_params$rts, model_params$orientation,
input$dea_dl_format)
},
content = function(file) {
p <- dea_plot() +
Expand Down Expand Up @@ -457,7 +460,9 @@ shinyServer(function(input, output, session) {

output$salter.save <- downloadHandler(
filename = function() {
sprintf('salterplot-%s.%s', Sys.Date(), input$salter_dl_format)
sprintf(
'salterplot-%s-%s.%s', model_params$rts, model_params$orientation,
input$salter_dl_format)
},
content = function(file) {
ggsave_(
Expand All @@ -474,28 +479,50 @@ shinyServer(function(input, output, session) {
eff <- dea.prod()$eff

if (model_params$orientation == 'in')
sum.eff <- sum(dea.in() * eff) / sum(dea.in())
sum_eff <- sum(dea.in() * eff) / sum(dea.in())
else if (model_params$orientation == 'out')
sum.eff <- sum(dea.out() * eff) / sum(dea.out())

rts <- switch(dea.prod()$RTS,
crs = 'constant returns to scale',
vrs = 'variable returns to scale',
drs = 'non-increasing returns to scale',
irs = 'non-decreasing returns to scale',
'UNKNOWN'
sum_eff <- sum(dea.out() * eff) / sum(dea.out())

rts <- switch(
dea.prod()$RTS,
crs = 'Constant',
vrs = 'Variable',
drs = 'Non-increasing',
irs = 'Non-decreasing'
)

orient <- switch(dea.prod()$ORIENTATION,
'in' = 'input oriented',
'out' = 'output oriented',
'UNKNOWN'
orient <- switch(
dea.prod()$ORIENTATION,
'in' = 'Input',
'out' = 'Output'
)

list(
p(list('Technology is ', tags$em(rts), ' and orientation is ', tags$em(orient))),
p(paste('Mean efficiency:', round(mean(eff), input$dea_round))),
p(paste('Weighted efficiency:',round(sum.eff, input$dea_round))),
p(class = 'lead', 'Summary'),
layout_column_wrap(
width = 1/4,
value_box(
title = 'Technology',
rts,
theme = 'secondary'
),
value_box(
title = 'Orientation',
orient,
theme = 'secondary'
),
value_box(
'Mean efficiency',
round(mean(eff), input$dea_round),
theme = 'primary'
),
value_box(
'Weighted efficiency',
round(sum_eff, input$dea_round),
theme = 'primary'
)
),
p(class = 'lead', 'Statistics on efficiency scores'),
layout_column_wrap(
width = 1/5,
card(
Expand All @@ -519,12 +546,25 @@ shinyServer(function(input, output, session) {
card_body(round(max(eff), input$dea_round))
)
),
hr(),
renderTable({ eff_tbl }),
renderPlot({
hist(eff, col = 'red', xlab = 'Efficiency',
main = 'Distribution of efficiency scores')
})
p(class = 'lead', 'Distribution'),
layout_columns(
col_widths = c(4, 8),
renderTable({ eff_tbl }),
renderPlot({
# Find to optimal number of bins using Freedman-Diaconis rule if N is less
# than 200, and Sturge's rule if N is equal or greater than 200
n_bins <- if (length(eff) < 200) nclass.FD(eff) else nclass.Sturges(eff)
bins <- pretty(range(eff), n = n_bins, min.n = 1)
ggplot(data.frame(eff = eff), aes(x = eff)) +
stat_bin(fill = '#ee2255', color = '#eeeeee', breaks = bins) +
geom_rug() +
theme_pioneer() +
theme(
axis.title.x = element_blank(),
axis.title.y = element_blank()
)
})
)
)

})
Expand Down Expand Up @@ -612,7 +652,9 @@ shinyServer(function(input, output, session) {

output$exporttable <- downloadHandler(
filename = function() {
paste0('dea-model-', Sys.Date(), '.', input$exportfileformat)
sprintf(
'dea-model-%s-%s.%s', model_params$rts, model_params$orientation,
input$exportfileformat)
},
content = function(file) {
df <- dea.tbl()
Expand Down Expand Up @@ -867,20 +909,16 @@ shinyServer(function(input, output, session) {
# Add DMU names and round inputs
df <- cbind(data.frame(DMU = names(dea.prod()$eff)), round(res$tbl, input$boot_round))

tbl <- reactable(
df,
class = 'small',
striped = TRUE,
defaultPageSize = 30,
pageSizeOptions = c(10, 30, 50, 100),
columns = list(
opts <- list2(!!!reactable_opts, data = df, columns = list(
eff = colDef(show = input$boot_show_eff, name = 'Efficiency'),
bias = colDef(show = input$boot_show_bias, name = 'Bias'),
eff_bc = colDef(name = 'Bias corr. score'),
lower = colDef(name = 'Lower bound'),
upper = colDef(name = 'Upper bound')
upper = colDef(name = 'Upper bound'),
range = colDef(name = 'CI range')
)
)
tbl <- do.call(reactable, opts)

# Add warning if there are any missing observations
if (!is.null(res$missing)) {
Expand All @@ -900,6 +938,28 @@ shinyServer(function(input, output, session) {
}
})

output$boot_export <- downloadHandler(
filename = function() {
sprintf(
'bootstrap-%s-%s.%s', model_params$rts, model_params$orientation,
input$boot_fileformat)
},
content = function(file) {
res <- dea_boostrap()
df <- cbind(data.frame(DMU = names(dea.prod()$eff)), round(res$tbl, input$boot_round))
# Export based on chosen file format
if (input$boot_fileformat == 'dta') {
colnames(df) <- gsub('\\s', '_', colnames(df))
colnames(df) <- gsub('[^A-Za-z0-9_]', '', colnames(df))
haven::write_dta(df, file)
} else if (input$boot_fileformat == 'xlsx') {
writexl::write_xlsx(df, file)
} else if (input$boot_fileformat == 'csv') {
write.csv2(df, file, fileEncoding = 'CP1252', row.names = FALSE)
}
}
)

# ---- Malmquist ----

output$malm.dt <- renderUI({
Expand Down Expand Up @@ -982,7 +1042,9 @@ shinyServer(function(input, output, session) {
)

output$`export-dea-rds` <- downloadHandler(
filename = 'dea.rds',
filename = function() {
sprintf('dea-%s-%s.rds', model_params$rts, model_params$orientation)
},
content = function(file) {
d <- selection()
saveRDS(d, file = file)
Expand Down
10 changes: 10 additions & 0 deletions inst/app/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ ui <- function(request) { page_navbar(
numericInput('boot_round', 'Number of decimals', min = 1L, max = 15L, step = 1L, value = 4L),
checkboxInput('boot_show_eff', 'Show original efficiency score', value = TRUE),
checkboxInput('boot_show_bias', 'Show bias', value = FALSE)
),
accordion_panel(
title = 'Export',
downloadButton('boot_export', 'Export results', class = 'btn-dark'),
p(class = 'small', helpText(
'Download the bootstrap results as shown in the table to the right.'
)),
selectizeInput(
'boot_fileformat', 'Choose file format',
choices = c('Excel' = 'xlsx', 'Stata' = 'dta', 'Comma separated values' = 'csv'))
)
),
actionButton('run_boot', 'Run bootstrap', class = 'btn-primary btn-sm')
Expand Down
14 changes: 5 additions & 9 deletions inst/app/www/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,13 @@ h2 {
background-color: #edf389;
}

.irs-grid-pol.small {
display: none;
}

.dataTables_info, .dt-buttons {
width: 50%;
text-align: left;
#ui_inputs .selectize-input, #ui_outputs .selectize-input {
max-height: 4rem;
overflow-y: scroll;
}

.dataTables_length, .dataTables_paginate {
width: 50%;
.irs-grid-pol.small {
display: none;
}

.form-control {
Expand Down

0 comments on commit 2ec54fb

Please sign in to comment.