Skip to content

Commit

Permalink
data export button for the graph in the Bivariate Correlation tab #322
Browse files Browse the repository at this point in the history
  • Loading branch information
kannanv93 committed Dec 10, 2024
1 parent a8ff3a6 commit b5b08c4
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 4 deletions.
14 changes: 12 additions & 2 deletions app/auxiliary/plots.R
Original file line number Diff line number Diff line change
Expand Up @@ -1786,7 +1786,17 @@ static_scatter <-
"y: ", {{yvar}} , "<br>", "<br>"
)
)



sc_data<-data %>%
select(country_code, country_name, income_group, region, country_group, x, y)

sc_data<- sc_data %>%
rename(
!!x_scatter := x, # Rename 'x' to the value in x_scatter
!!y_scatter := y # Rename 'y' to the value in y_scatter
)

#PLOTTING THE SCATTER PLOT
sc_plot <- ggplot(
data,
Expand Down Expand Up @@ -1867,7 +1877,7 @@ static_scatter <-
}else
sc_plot <- sc_plot

return(sc_plot)
return(list(sc_plot = sc_plot, sc_data = sc_data))
}

interactive_scatter <-
Expand Down
65 changes: 64 additions & 1 deletion app/server.R
Original file line number Diff line number Diff line change
Expand Up @@ -1991,7 +1991,7 @@ server <- function(input, output, session) {
input$linear_fit,
input$color_base_scatter,
input$color_comp_scatter
) %>%
)$sc_plot %>%
interactive_scatter(
input$y_scatter,
input$x_scatter,
Expand Down Expand Up @@ -2418,6 +2418,62 @@ server <- function(input, output, session) {
}
)

# Downloadable csv of Bivariate dataset

observe({
# Check the condition

inputs_not_blank <- input$country_scatter != "" &&
input$y_scatter != "" &&
input$x_scatter != ""

# Check the condition using check_data and input completeness
condition <- inputs_not_blank &&
check_data(global_data, input$country_scatter, input$y_scatter, input$x_scatter) == FALSE

# Show or hide the button based on the condition
if (condition) {
shinyjs::show("download_bivariate_data")
} else {
shinyjs::hide("download_bivariate_data")
}
})


output$download_bivariate_data <-
downloadHandler(
filename = function() {
paste0("CLIAR Bivariate Analysis-",input$country_scatter," - data.csv")
},
content = function(file) {

show_modal_spinner(
color = "#17a2b8",
text = "Loading Data",
)

on.exit(remove_modal_spinner())

write_csv(
static_scatter(
global_data,
input$country_scatter,
input$countries_scatter,
high_group(),
input$y_scatter,
input$x_scatter,
variable_names,
country_list,
input$linear_fit,
input$color_base_scatter,
input$color_comp_scatter
)$sc_data,
file,
na = "")
}
)




# Report ================================================================================
Expand Down Expand Up @@ -2843,6 +2899,13 @@ server <- function(input, output, session) {
shinyjs::show("download_data_1")
})

observeEvent(input$family, {
if (input$family == "SOE Corporate Governance" || input$family == "Labor and Social Protection Institutions" )
shinyjs::hide("download_data_1")
else
shinyjs::show("download_data_1")
})



## Save inputs to be loaded the next time --------------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion app/ui.R
Original file line number Diff line number Diff line change
Expand Up @@ -1013,7 +1013,17 @@ ui <-
value = FALSE,
status = "success"
)
)
),
column(
width = 6),
column(
width = 2.4,
shinyjs::hidden(downloadButton(
"download_bivariate_data",
"Download Chart Data",
style = "width:100%; background-color: #204d74; color: white"
))
),
)
),

Expand Down

0 comments on commit b5b08c4

Please sign in to comment.