But somehow it wants me to define an environment for the table I create with kable. How can I do that? It took me quite some time to adapt the layout for my tables and plots in the .Rmd file and now R does not seem to recognize any of it.
The problem is not on the R side, but on pandoc / LaTeX side. The ! LaTeX Error: Environment tabu undefined message means that a required LaTeX macro is not defined.
I found it rather common problem with Rmarkdown. It can get a bit confusing when using the default templates; as a solution I built my own .tex template, over which I have full control and in which I include all the necessary LaTeX calls (in your case \usepackage{tabu} seems to be missing).
Your can have a look at my Github RPTG repository, and have a look at my template. It is unlikely to suit your needs as it is, but it could be an inspiration for you to make your own.
Thank you for you help. Unfortunately, this does not seem to change anything for my problem. But I will keep it in mind in case this problem appears. I have never used "shiny", so I am not familiar with its implementation.
It is, indeed, very confusing as it works perfectly fine when just knitting it directly from the .Rmd-file. This is what I find so confusing. At that point the LaTeX macro seems to be there.
I thought that "render" basically does the same thing as knitting and is just called from another place - the Rscript.
My problem is, that I am not familiar with LateX. So, I don't have any idea how it works. I will try to follow your example and see if I can built my own .tex template.
But how and where would I then include it? In my R.file or in the .Rmd-file or do I need to call it when using the render function?
copy the Report.tex template from my github to your working directory (or someplace else, and use the full path; working directory makes debugging easier)
in the YAML heading of your .Rmd file include this reference:
I realize this is probably old news by now, but I remembered there is an easier way to get the {tabu} LaTeX macro to work than building it into a a custom tex template: include it in header-includes section of the YAML header of your Rmd file.
For example (copied from http://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf by Hao Zhu)