'Rmarkdown document not rendering properly in Shiny App

I have a parametrized rmarkdown document based on Shiny inputs.

The rmarkdown pdf renders properly when the app runs locally. However when hosted on the shiny server it produces \end{landscape} at the end of each table.

Here is a snippet of the rmarkdown code:

---
title: "Custom Analysis Report"
date: "Last compiled on `r format(Sys.time(), '%d %B, %Y')`"
output:
  pdf_document:
mainfont: Times New Roman
fontsize: 11pt

header-includes:
- \usepackage{booktabs}
- \usepackage{longtable}
- \usepackage{array}
- \usepackage{multirow}
- \usepackage{wrapfig}
- \usepackage{float}
- \usepackage{colortbl}
- \usepackage{pdflscape}
- \usepackage{lscape}
- \usepackage{tabu}
- \usepackage{threeparttable}
- \usepackage{threeparttablex}
- \usepackage[normalem]{ulem}
- \usepackage{makecell}
- \usepackage{xcolor}


always_allow_html: true
---

```{r setup, include=FALSE}
library(knitr)
library(kableExtra)


```

```{r echo = FALSE , warning = FALSE, message = FALSE, eval = TRUE , results='asis'}
if (nrow(org_profile_df1()) >= 1){
  
options(knitr.kable.NA = 'NA')  
  org_profile_df1() %>%
  kable(align = "l", 
      format    = "latex", 
      longtable = T, 
      booktabs  = T, 
      
      caption   = "Organizational Profile") %>%
  kable_classic(full_width = F) %>%
   # column_spec(1, bold = T, color = "red") %>% 
  kable_styling(latex_options = c("repeat_header", "bordered", "striped"),font_size = 4, position = "left",
                                  #,"striped", "scale_down"),
              repeat_header_continued = "\\textit{(Continued on Next Page...)}") %>% 
   #kable_paper(full_width = T) %>%
  row_spec(0, bold = T) %>% landscape()

}
options(knitr.kable.NA = '-')


```

org_profile_df1() is a reactive dataset that is generated by shiny parameters. There are other such reactive datasets that get generated based on whether they exist or not (the if-statements). After every one of these tables a blank page with \end{landscape} appears (see also picture). However when I run the shiny app locally this does not appear. Only when the app is hosted on Shinyapps.io does this occur.

I have included a picture of a reactive table. There are special characters such as % and : in the reactviely generated tables.

occurs after every table sample reactive table



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source