Skip to content

Commit

Permalink
App feature improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Jenkins committed Apr 12, 2024
1 parent b1f541e commit 21bdc97
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 22 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ importFrom(shiny,tags)
importFrom(shiny,textAreaInput)
importFrom(shiny,textInput)
importFrom(shiny,uiOutput)
importFrom(shiny,updateNumericInput)
importFrom(shinyjs,runjs)
3 changes: 2 additions & 1 deletion R/app_server.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ app_server <- function(input, output, session) {
bar_labels = mod_bar_params_outputs[["param_bar_labels"]],
flip_axes = mod_bar_params_outputs[["param_flip_axes"]],
facet_col = mod_bar_params_outputs[["param_facet_col"]],
facet_row = mod_bar_params_outputs[["param_facet_row"]]
facet_row = mod_bar_params_outputs[["param_facet_row"]],
y_label = mod_bar_params_outputs[["param_y_label"]]

)

Expand Down
2 changes: 1 addition & 1 deletion R/app_ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ app_ui <- function() {
class = "custom-navbar",
style = "background: #18bc9c; color: white; padding: 10px; margin-bottom: 5px;",
span(
span(icon("chart-pie", style = "margin-right: 5px;"), strong("mapmixture"), span(class = "badge bg-light mx-1", "1.1.0")),
span(icon("chart-pie", style = "margin-right: 5px;"), strong("mapmixture"), span(class = "badge bg-light mx-1", "1.1.1")),
a(
style = "color: white;",
href = "https://twitter.com/tom__jenkins",
Expand Down
4 changes: 2 additions & 2 deletions R/func_structure_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ structure_plot <- function(admixture_df,
ggplot2::annotate("segment",
x = site_position, xend = site_position,
y = rep(site_ticks_size, length(site_position)), yend = 0,
colour = "black", linewidth = 1
colour = "black", linewidth = 0.8
)
}

Expand Down Expand Up @@ -212,7 +212,7 @@ structure_plot <- function(admixture_df,
ggplot2::annotate("segment",
x = site_position, xend = site_position,
y = rep(site_ticks_size, length(site_position)), yend = 0,
colour = "black", linewidth = 1
colour = "black", linewidth = 0.8
)
}

Expand Down
13 changes: 6 additions & 7 deletions R/mod_bar_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ mod_barplot_plot_server <- function(id, bttn, admixture_df,
site_divider, divider_lwd,
site_ticks, ticks_size,
site_labs_size, site_labs_x, site_labs_y,
flip_axes, facet_col, facet_row

flip_axes, facet_col, facet_row, y_label
) {
moduleServer(id, function(input, output, session) {
ns <- session$ns
Expand All @@ -46,7 +45,6 @@ mod_barplot_plot_server <- function(id, bttn, admixture_df,
# runjs("clearPlotOutput('bar')")
# })


# Create barplot as reactive ----
output_barplot <- reactive({
req(admixture_df())
Expand All @@ -68,7 +66,8 @@ mod_barplot_plot_server <- function(id, bttn, admixture_df,
site_labels_y = site_labs_y(),
flip_axis = flip_axes(),
facet_col = facet_col(),
facet_row = NULL
facet_row = NULL,
ylabel = y_label()
)

# Return plot
Expand Down Expand Up @@ -117,10 +116,10 @@ mod_barplot_plot_server <- function(id, bttn, admixture_df,
# Render download button and internal components ----
runjs("document.getElementById('bar_plot-dropdown_download_bttn').classList.remove('hidden');")
output$dropdown_download_bttn <- renderUI({
div(id = "download_bttn_display", style = "position: relative; margin-bottom: -20px; float: right; margin-top: 1px;",
div(id = "bar_download_bttn_display", style = "position: relative; margin-bottom: -20px; float: right; margin-top: 1px;",
shinyWidgets::dropdown(
style = "simple", icon = icon("download"), status = "success", size = "sm", right = TRUE, width = "300px",
strong("Download Map", class = "fs-4 text-success"),
strong("Download Barplot", class = "fs-4 text-success"),
shinyWidgets::radioGroupButtons(
inputId = ns("filetype_radio_bttn"),
label = strong("Choose File Type:"),
Expand Down Expand Up @@ -221,7 +220,7 @@ mod_barplot_plot_server <- function(id, bttn, admixture_df,
})


# Download map when button is clicked ----
# Download barplot when button is clicked ----
output$download_bttn <- downloadHandler(
filename = function() {
ifelse(input$filetype_radio_bttn == "PNG", paste0("Barplot_figure", ".png"),
Expand Down
30 changes: 21 additions & 9 deletions R/mod_barplot_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ mod_barplot_params_ui <- function(id) {
),
br(),

# Y label ----
textInput(
inputId = ns("bar_y_label"),
label = strong("Y Label"),
value = "Proportion",
width = "275px"
),

# Labels to display (sites or individuals) button ----
shinyWidgets::radioGroupButtons(
inputId = ns("bar_labels_bttn"),
Expand Down Expand Up @@ -71,9 +79,9 @@ mod_barplot_params_ui <- function(id) {
br(),

# Site labels size, x and y positions ----
div(style = "display: inline-block;", numericInput(ns("bar_site_labs_size"), label = strong("Label Size"), width = "80px", min = 0, value = 2)),
div(style = "display: inline-block;", numericInput(ns("bar_site_labs_x"), label = strong("Label X"), width = "80px", value = 0)),
div(style = "display: inline-block;", numericInput(ns("bar_site_labs_y"), label = strong("Label Y"), width = "80px", value = 1, min = 0, max = 2, step = 0.01)),
div(style = "display: inline-block;", numericInput(ns("bar_site_labs_size"), label = strong("Site Size"), width = "80px", min = 0, value = 2)),
div(style = "display: inline-block;", numericInput(ns("bar_site_labs_x"), label = strong("Site X"), width = "80px", value = 0)),
div(style = "display: inline-block;", numericInput(ns("bar_site_labs_y"), label = strong("Site Y"), width = "80px", value = 1, min = -2, max = 2, step = 0.1)),
br(),

# Site ticks ----
Expand All @@ -94,9 +102,9 @@ mod_barplot_params_ui <- function(id) {
inputId = ns("bar_site_ticks_size"),
label = NULL,
value = 1,
min = 0,
max = 2,
step = 0.01,
min = -5,
max = 5,
step = 0.1,
width = "80px"
)
),
Expand Down Expand Up @@ -221,14 +229,14 @@ mod_barplot_params_server <- function(id, admixture_df){
# Import ticks and tick size chosen by user ----
user_ticks <- reactive(input$bar_site_ticks)
user_ticks_size <- reactive({
return(input$bar_site_ticks_size-1 +-0.01)
return(-0.01 - input$bar_site_ticks_size/500)
})

# Import site labels size, x and y positions ----
user_site_labs_size <- reactive(input$bar_site_labs_size)
user_site_labs_x <- reactive(input$bar_site_labs_x)
user_site_labs_y <- reactive({
return(input$bar_site_labs_y-1 +-0.025)
return(-0.025 - input$bar_site_labs_y/100)
})

# Import flip axis chosen by user ----
Expand All @@ -244,6 +252,9 @@ mod_barplot_params_server <- function(id, admixture_df){
if (!is.na(input$bar_facet_row)) return(input$bar_facet_row)
})

# Import y label chosen by user ----
user_y_label <- reactive(input$bar_y_label)

# Update facet_col with the maximum number of sites
observeEvent(admixture_df(), {
updateNumericInput(
Expand Down Expand Up @@ -271,7 +282,8 @@ mod_barplot_params_server <- function(id, admixture_df){
param_bar_labels = user_bar_labels,
param_flip_axes = user_flip_axes,
param_facet_col = user_facet_col,
param_facet_row = user_facet_row
param_facet_row = user_facet_row,
param_y_label = user_y_label
)
)

Expand Down
2 changes: 1 addition & 1 deletion R/mod_main_plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ mod_main_plot_server <- function(id, bttn, admixture_df, coords_df,
# Render download button and internal components ----
runjs("document.getElementById('main_plot-dropdown_download_bttn').classList.remove('hidden');")
output$dropdown_download_bttn <- renderUI({
div(id = "download_bttn_display", style = "position: relative; margin-bottom: -20px; float: right; margin-top: 1px;",
div(id = "map_download_bttn_display", style = "position: relative; margin-bottom: -20px; float: right; margin-top: 1px;",
shinyWidgets::dropdown(
style = "simple", icon = icon("download"), status = "success", size = "sm", right = TRUE, width = "300px",
strong("Download Map", class = "fs-4 text-success"),
Expand Down
4 changes: 3 additions & 1 deletion inst/www/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ function clearPlotOutput (plot) {
if (plot == "map") {
document.getElementById("main_plot-admixture_map").textContent = "";
document.getElementById("main_plot-dropdown_download_bttn").classList.add("hidden");
document.getElementById("map_download_bttn_display").classList.add("hidden");
}

// Do this for bar
if (plot == "bar") {
document.getElementById("bar_plot-admixture_barplot").textContent = "";
/* document.getElementById("main_plot-dropdown_download_bttn").classList.add("hidden");*/
document.getElementById("bar_plot-dropdown_download_bttn").classList.add("hidden");
document.getElementById("bar_download_bttn_display").classList.add("hidden");
}
};
20 changes: 20 additions & 0 deletions inst/www/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@
border-color: white;
}

#bar_plot-download_bttn:active {
background-color: #14a085;
border-color: white;
}

#bar-download_bttn {
float: right;
padding-right: 40px;
padding-top: 5px;
}

.sidebar-container {
overflow-y: scroll;
}
Expand Down Expand Up @@ -148,3 +159,12 @@
.param-bttn-100px {
width: 100px !important;
}

/*Hide the site order elements (future feature)*/
#barplot_params-bar_site_order-label {
display: none;
}
#barplot_params-bar_site_order {
display: none;
}

0 comments on commit 21bdc97

Please sign in to comment.