Skip to content

Commit

Permalink
Improving style in planet module
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrsch committed Jan 31, 2025
1 parent 1f581ee commit adcb180
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions app/view/planet.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
box::use(
dplyr[distinct, filter, pull, rename, select],
plotly[layout, plot_ly, plotlyOutput, renderPlotly],
shiny.fluent[Dropdown.shinyInput, updateDropdown.shinyInput],
plotly[config, layout, plot_ly, plotlyOutput, renderPlotly],
shiny.fluent[Dropdown.shinyInput, Toggle.shinyInput, updateDropdown.shinyInput],
shiny[div, getDefaultReactiveDomain, moduleServer, NS, observeEvent, req],
stats[na.omit],
)
Expand All @@ -10,7 +10,7 @@ box::use(
app/logic/data[continents, ghg_capita_globe_map, ghg_gdp_globe_map, ghg_sector_globe_map],
app/logic/data[ghg_totals_globe_map, globe_cc],
app/logic/get_options[get_options],
app/logic/top_regions_help[get_countries_he],
app/logic/top_regions_help[get_countries_he, get_plot_title],
app/view/emissions_by,
)

Expand Down Expand Up @@ -57,15 +57,18 @@ ui <- function(id) {
)
)
),
class = "ms-Grid-col ms-sm1 ms-md2"
class = "ms-Grid-col ms-sm1 ms-md2",
style = "padding-left: 20px;"
),
div(
plotlyOutput(ns("map"), height = "50rem"),
class = "ms-Grid-col ms-sm10 ms-md8"
),
div(
Toggle.shinyInput(label = "3D Globe", ns("is_3d_globe"), value = TRUE),
emissions_by$ui(ns("emissions_by")),
class = "ms-Grid-col ms-sm1 ms-md2"
class = "ms-Grid-col ms-sm1 ms-md2",
style = "padding-right: 20px;"
)
)
}
Expand All @@ -91,13 +94,15 @@ server <- function(id) {

output$map <- renderPlotly({
req(input$selected_countries)

Check warning on line 97 in app/view/planet.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/view/planet.R,line=97,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
# Extract selected keys properly
selected_countries <- globe_cc |>
filter(cc %in% input$selected_countries) |>
select(country) |>
pull() |>
na.omit()

# Get the plot data
filtered_data <- get_countries_he(
input$`emissions_by-emissions_by`,
selected_countries,
Expand All @@ -113,6 +118,15 @@ server <- function(id) {
cc = country,
value = emission
)

Check warning on line 121 in app/view/planet.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/view/planet.R,line=121,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
plot_title <- get_plot_title(
input$`emissions_by-emissions_by`,
input$`emissions_by-emissions_by_sectors`,
input$`emissions_by-emissions_by_substance`
)

Check warning on line 127 in app/view/planet.R

View workflow job for this annotation

GitHub Actions / Run linters and tests

file=app/view/planet.R,line=127,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
# Get the plot type
globe_type <- ifelse(input$is_3d_globe, "orthographic", "natural earth")

# Create Plotly map
plot_ly(
Expand All @@ -124,11 +138,14 @@ server <- function(id) {
colorscale = "Redor",
reversescale = FALSE
) |>
config(displayModeBar = "always") |>
layout(
title = paste0(plot_title, ", year 2023"),
margin = list(t = 80),
geo = list(
showframe = TRUE,
showcoastlines = TRUE,
projection = list(type = "orthographic")
projection = list(type = globe_type)
)
)
})
Expand Down

0 comments on commit adcb180

Please sign in to comment.