Skip to content

Commit

Permalink
Fix DOCX and PDF downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff-Thompson12 committed Jan 18, 2024
1 parent 8014bac commit 5e79d50
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
15 changes: 9 additions & 6 deletions R/mod_downloadHandler.R
Original file line number Diff line number Diff line change
Expand Up @@ -267,17 +267,20 @@ mod_downloadHandler_server <- function(id, pkgs, user, metric_weights){
downloads_plot <- build_comm_plotly(comm_data)
metric_tbl <- dbSelect("select * from metric", db_name = golem::get_golem_options('assessment_db_name'))

dep_metrics <- eventReactive(this_pkg, {
get_depends_data(this_pkg, db_name = golem::get_golem_options("assessment_db_name"))
})
dep_metrics <- get_depends_data(this_pkg, db_name = golem::get_golem_options("assessment_db_name"))

dep_cards <- build_dep_cards(data = dep_metrics(), loaded = session$userData$loaded2_db()$name, toggled = 0L)
dep_cards <- build_dep_cards(data = dep_metrics, loaded = session$userData$loaded2_db()$name, toggled = 0L)

dep_table <- purrr::map_df(dep_metrics()$name, ~get_versnScore(.x, session$userData$loaded2_db(), session$userData$repo_pkgs())) %>%
right_join(dep_metrics(), by = "name") %>%
dep_table <-
if (nrow(dep_metrics) == 0) {
dplyr::tibble(package = character(), type = character(), version = character(), score = character())
} else {
purrr::map_df(dep_metrics$name, ~get_versnScore(.x, session$userData$loaded2_db(), session$userData$repo_pkgs())) %>%
right_join(dep_metrics, by = "name") %>%
select(package, type, version, score) %>%
arrange(package, type) %>%
distinct()
}

# Render the report, passing parameters to the rmd file.
rmarkdown::render(
Expand Down
9 changes: 6 additions & 3 deletions inst/report_downloads/reportDocx.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ library(plotly)
knitr::opts_chunk$set(echo = F, fig.width = 5.5, fig.height = 3.4)
cm_ind <- nrow(params$com_metrics) != 0
dm_ind <- nrow(params$dep_table) != 0
```

```{r functions, include=FALSE, message=FALSE, warning=FALSE}
Expand Down Expand Up @@ -286,10 +287,12 @@ if('Community Usage Comments' %in% params$report_includes){

`r if ('Package Dependencies' %in% params$report_includes) {"\\* Metrics whose score is NA will not impact the package {riskmetric} score"}`

```{r package_dependencies_table}
```{r package_dependencies_table, eval=dm_ind}
if('Package Dependencies' %in% params$report_includes) {
flextable::flextable(params$dep_table, cwidth = c(1.5, 1.25, 1.25, 1.25)) %>%
flextable::set_table_properties(align = "left")
params$dep_table %>%
purrr::set_names(tools::toTitleCase(names(.))) %>%
flextable::flextable(cwidth = c(1.5, 1.25, 1.25, 1.25)) %>%
flextable::set_table_properties(align = "left")
} else ""
```

Expand Down
10 changes: 6 additions & 4 deletions inst/report_downloads/reportPdf.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ library(plotly)
options(tinytex.verbose = TRUE)
knitr::opts_chunk$set(echo = F, fig.width = 5.5, fig.height = 3.4)
cm_ind <- nrow(params$com_metrics) != 0
dm_ind <- nrow(params$dep_table) != 0
```

<!-- Fix Package fancyhdr Warning -->
Expand Down Expand Up @@ -298,12 +299,13 @@ if('Community Usage Comments' %in% params$report_includes){

`r if ('Package Dependencies' %in% params$report_includes) {"\\* Metrics whose score is NA will not impact the package {riskmetric} score"}`

```{r package_dependencies_table}
if('Package Dependencies' %in% params$report_includes) {
params$dep_table %>%
```{r package_dependencies_table, eval=dm_ind}
if('Package Dependencies' %in% params$report_includes) {
params$dep_table %>%
purrr::set_names(tools::toTitleCase(names(.))) %>%
kableExtra::kbl(format = 'latex', booktabs = T, linesep = "") %>%
kableExtra::kable_styling("basic", latex_options = "hold_position", full_width = F, position = 'left')
} else ""
} else ""
```

`r if(any(c('Source Explorer Comments') %in% params$report_includes)) {"\\newpage "}`
Expand Down

0 comments on commit 5e79d50

Please sign in to comment.