rmarkdown render report doesn't work on server: render params not declared in YAML

Code works in local R Studio but html report from Shiny server does not download. I checked logs:
Warning: Error in knit_params_get: render params not declared in YAML: projdata, userinfo
** [No stack trace available]**

Part of the code from server.R:

out <- rmarkdown::render('reppu_report_template.Rmd',
                             params = list(
                               data_BU = inter_data_filter_react_report(),
                               data_BU_month = inter_data_filter_react_report_month(),
                               organizations = input$inter_filter_org,
                               timelimit = input$inter_filter_time,
                               en_time = update_time(),
                               projdata = projdata(), 
                               userinfo = userinfo() 
                             ),
                             rmarkdown::html_document()
    )
    file.rename(out, file)

from Rmd part:


output: html_document
params:
text: 'NULL'
data_BU: 'NULL'
data_BU_month: 'NULL'
organizations: 'NULL'
timelimit: 'NULL'
en_time: 'NULL'
projdata: 'NULL'
userinfo: 'NULL'

This means that projdata and userinfo are not among the defined YAML fields under params.

Can you check the indendation of the fields in your Rmd file ? The above post does not allow to see if you got it ok. See FAQ: How to Format R Markdown Source

Also can you post the output of (by replacing with your filename)

knitr::knit_params(xfun::read_utf8("your-rmd-file-here.Rmd"))

thanks but knitting parameters separately didn't help so far.


output: html_document
params:
text: 'NULL'
data_BU: 'NULL'
data_BU_month: 'NULL'
organizations: 'NULL'
timelimit: 'NULL'
en_time: 'NULL'
projdata: 'NULL'
userinfo: 'NULL'

{r define_title, echo=FALSE, include=FALSE}

Define title from selected organizations

organizations_length <- length(params$organizations)

if (organizations_length >= 5){
titletext <- paste0("Report for ",organizations_length, " selected organizations")
} else(
titletext <- paste0("Report for organizations ", params$organizations)
)

r titletext

Selected timeframe: r params$timelimit

Data last updated at: r params$en_time

{r, include=FALSE}

library(kableExtra)
library(dplyr)
library(ggplot2)
library(lubridate)
library(tidyr)

path <- ifelse(getwd() == "/home/rstudio/reppudashdev",
yes = "/home/rstudio/reppudashdev",
no = "/srv/shiny-server/reppudashboard")

source(paste0(path,"/functions/reppuFunctions.R"), local = TRUE)

{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

Part of the code where userinfo and projdata are used to produce plots

{r plotbox2, echo=FALSE, out.width = "100%", fig.align = "center", fig.asp=0.3}

projectsum_BU <- params$data_BU %>%
filter(Total > 0) %>%
distinct(cscprjnum) %>%
count()

startyear <- parse_date_time(params$timelimit[1],"ym") %>% year()
endyear <- parse_date_time(params$timelimit[2],"ym") %>% year()

userdata <- userinfo()

usersum <- userdata %>%
filter(logindisabled != TRUE | is.na(logindisabled)) %>%
filter(year >= startyear & year <= endyear) %>%
distinct(id_user) %>%
count()

startInterval <- as.Date(parse_date_time(params$timelimit[1],"ym"))
stopInterval <- as.Date(parse_date_time(params$timelimit[2],"ym"))

times <- interval(startInterval, stopInterval + months(1) - days(1) )

projectdata <- projdata()
opened_projects <- projectdata %>%
filter(!is.na(cscprjopendate) & cscprjopendate %within% times & cscprjscope != "personal") %>%
select(cscprjnum) %>%
distinct(cscprjnum) %>%
count()

df <- data.frame(
x = rep(seq(2, 21.5, 6.5), 4) %>% head(3),
y = c(rep(11, 4), rep(6.5, 4), rep(2,4)) %>% head(3),
h = rep(4.25, 3),
w = rep(6.25, 3),
value = c(projectsum_BU$n, opened_projects$n, usersum$n),
info = c("Projects using BUs","New projects opened \n (excl. personal projects)","Users able to log in"),
color = factor(1:3))

ggplot(df, aes(x, y, height = h, width = w, label = info)) +
geom_tile(aes(fill = color)) +
geom_text(color = "#64676b", fontface = "bold", size = 6,
aes(label = value, x = x - 2.9, y = y + 1), hjust = 0) +

geom_text(color = "#64676b", size = 4,
aes(label = info, x = x - 2.9, y = y - 1), hjust = 0) +
coord_fixed() +
scale_fill_manual(values = dashboard_palette(df$info))+
theme_void() +
guides(fill = "none")

I am not sure I understand what you tried here.

Also the formatting is still not correct so really hard to read.

the result of this command would be helpful

Does the report render fine if you call this locally in a new fresh R session, with all the parameters being the expecting one ?

I tried to use knitr::knit_params(xfun::read_utf8("your-rmd-file-here.Rmd")) but it didn't help.

This is part of the server.R in shiny App which produces report. My idea is to generate a reactive report from Shiny application.

I also specified the path for the file. It's the same directory where shiny app is.

I would like to see the result of this where you have obviously replace "your-rmd-file-here.Rmd" in there by the actual path of your Rmd file. This should tell us how parameters are parsed within your file.

You could also provide us with a Github repo as reprex with everything I need to reproduce.

I don't understand this, and it is not reproducible on my side as absolute path are used. Maybe that is the cause and wrong paths are used when deployed ?

did it worked ?

As I mentioned twice already, Please do reformat your issue by editing the post above so that it can help us help you !

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.