I 've adopted your method to my work, but can't make it work as expected. Could you please help? Thanks in advance
---
title: ''
output:
pdf_document:
latex_engine: xelatex
urlcolor: blue
classoption: landscape
---
```{r prelim, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
knitr::opts_chunk$set(warning = FALSE)
knitr::opts_chunk$set(message = FALSE)
knitr::opts_chunk$set(dev = 'pdf', fig.width = 12, fig.height = 7)
library(dplyr)
library(ggplot2)
library(ggpubr)
library(gridExtra)
library(kableExtra)
library(cowplot)
library(glue)
```
```{r create_ds}
# summary page data
sum_tbl <- data.frame(
stringsAsFactors = FALSE,
subj_cd = c("CAB-01", "CAB-03", "CAB-05", "CAB-07"),
subj_name = c("Math","Physics","Chemistry","English"),
Score = c(95, 94, 100, 100),
St_Score = c(92,84,92,93)
)
# histogram data
his_tbl<-data.frame(
Score = c(99.669,99.487,100,100,99.475,99.452,
100,100,98.028,100,100,99.153,99.577,100,99.785,99.433,
100,100,99.441,100,98.778,99.56,100,99.446,100,99.234,
100,99.281,99.177,98.936,99.048,100,96.154,100,99.718,
99.481,99.765,99.811,100,100,100,100,97.544,99.457,
100,100,97.611,97.17,99.752,97.99,97.674,100,100,99.888,
100,99.419,100,99.76,100,99.754,100,99.287,97.273,
98.381,99.476,100,99.389,100,99.802,99.559,100,99.842,
100,100,100,99.438,100,99.855,99.769,100,100,99.707,100,
99.718,100,97.877,100,100,99.816,98.725,100,100,
99.378,100,99.825,99.512,99.827,99.677,100,98.983)
)
# table display data
dp_tbl <- data.frame(
stringsAsFactors = FALSE,
date = c("2019Q3-2020Q3"),
Score = c(99.65),
cnt = c(1541),
st_s = c(99.54),
nat_s = c(99.57),
p = c(39)
)
```
```{r func_def}
g_hist <- function(){
ggplot(his_tbl,aes(x=Score, y=..count..)) +
geom_histogram(bins=50, fill="steelblue", color="white") +
theme(title=element_text(size=11,face='bold'))
}
d_tab <- function() {
wide <- dp_tbl %>% select(
"Reporting Period"=date,
"School's Score"=Score,
"Number of School Reporting"=cnt,
"State Score"=st_s,
"National Score"=nat_s,
"School Percentile"=p)
long <- t(wide)
ggtexttable(long, cols = NULL,theme = ttheme("blank",tbody.style = c(hjust=1, x=0.9)))
}
```
This is a sample report for school subjects evaluation in pdf format. It has summary and detail pages. The first page is report description. 2nd page is a subject table with 4 rows as example (it has more then 40 rows in real). I want to have a internal link column, say SubjectID, and jump to desired detail page when click on it. For example, when click on CAB-01, it leads to Math detail page. I've used 'glue' to create a label, but some parts are missing; it don't work for me. Help needed. Thanks!
\pagebreak
**School ID: ** School 12345, IL
**Comparative Report: Subject Scores for School with National and State Comparison**
\
\
```{r sumpg, echo=FALSE}
sum_tblt <- sum_tbl %>%
select(
"SubjectID"=subj_cd,
"Subject Description"=subj_name,
"School's Score"=Score,
"State Score"=St_Score
)
sum_tblt <- as_tibble(sum_tblt)
sum_tblt %>%
mutate(SubjectID = glue("\\hyperref[tab:ids<<SubjectID>>]{<<SubjectID>>}",
.open = "<<", .close = ">>")) %>%
kable(format = "latex", escape = FALSE) %>%
column_spec(1, width="2cm", border_left = TRUE) %>%
column_spec(2:3, width="2.5cm") %>%
column_spec(4, width="2.5cm", border_right = TRUE)%>%
kable_styling("bordered", font_size = 12)
```
\pagebreak
**School: ** School 12345, IL
**Subject Name: ** Math
**Subject Description: ** Evaluation Report
**Link to QA Resources:** <http://rmarkdown.rstudio.com> {CAB-01}
```{r echo=F}
o2 <- g_hist()
o3 <- d_tab()
text <- paste(" ")
text.p <- ggparagraph(text = text, color="white")
top_row <- plot_grid(o3, text.p, align = 'h', axis="r")
bottom_row <- plot_grid(o2, align = 'h', axis="l")
ggarrange(top_row, bottom_row, ncol = 1, nrow = 2, heights = c(.6, 1))
```
\pagebreak
**School: ** School 12345, IL
**Subject Name: ** Physics
**Subject Description: ** Evaluation Report
**Link to QA Resources:** <http://rmarkdown.rstudio.com> {CAB-03}
```{r phypg,echo=F}
o2 <- g_hist()
o3 <- d_tab()
text <- paste(" ")
text.p <- ggparagraph(text = text, color="white")
top_row <- plot_grid(o3, text.p, align = 'h', axis="r")
bottom_row <- plot_grid(o2, align = 'h', axis="l")
ggarrange(top_row, bottom_row, ncol = 1, nrow = 2, heights = c(.6, 1))
```