I'm trying to make an R Shiny app with Rhino framework. I want to modify a dataframe in a logic module based on the input from a view module. But I suffered an error:
Loading required package: shiny
Error in box::use(app/main) :
i In argument: `season %in% c(season_input())`.
Caused by error in `season_input()`:
! could not find function "season_input"
This is the code in the view module called season_input.R:
box::use(
shiny[moduleServer, NS, selectInput, reactive],
)
box::use(
app/logic/init_dfs
)
#' @export
ui <- function(id){
ns <- NS(id)
selectInput(
inputId = "season_year",
label = "Select Season Year",
choices = list(
"seasons" = init_dfs$transfer_df$season |> unique()
),
multiple = T,
selectize = T
)
}
#' @export
server <- function(id){
moduleServer(id, function(input, output, session){
selected_seasons <- reactive(input$season_year)
})
}
Below is the logic module that requires input from the previous view module that will use the input to transform a dataframe
box::use(
dplyr[filter, group_by, summarise, ungroup, arrange, slice_head, left_join]
)
box::use(
app/logic/init_dfs,
app/view/season_input
)
transfers_df <- init_dfs$transfer_df |>
left_join(init_dfs$longlat_df, by = c("country_2" = "c2_name"), keep = F)
# 1st transform
top10country_byfee_arrivals1 <-
transfers_df |>
filter(
season %in% c(season_input()),
transfer_type == "Arrivals"
) |>
group_by(country_2) |>
summarise(sum_fee = sum(transfer_fee)) |>
ungroup() |>
arrange(desc(sum_fee)) |>
slice_head(n = 10)
top10country_byfee_departures1 <-
transfers_df |>
filter(
season %in% c(season_input()),
transfer_type == "Departures"
) |>
group_by(country_2) |>
summarise(sum_fee = sum(transfer_fee)) |>
ungroup() |>
arrange(desc(sum_fee)) |>
slice_head(n = 10)
# 2nd transform
top10country_byfee_arrivals2 <-
top10country_byfee_arrivals1 %>%
left_join(transfers_df %>% filter(transfer_type=="Arrivals"), by = "country_2") %>%
select(country_2, centroid_longitude, centroid_latitude, transfer_type, sum_fee) %>% distinct()
top10country_byfee_departures2 <-
top10country_byfee_departures1 %>%
left_join(transfers_df %>% filter(transfer_type=="Departures"), by = "country_2") %>%
select(country_2, centroid_longitude, centroid_latitude, transfer_type, sum_fee) %>% distinct()
# 3rd transform
top10country_byfee <- bind_rows(top10country_byfee_arrivals2, top10country_byfee_departures2) %>% arrange(desc(sum_fee))
#'@export
top10country_byfee