I build a shiny App that lets the user download a pdf report using r markdown.
The user can select an ID and variables (such as Dates...) from a data frame corresponding to this ID are printed in the .Rmd document.
The code inside the .Rmd looks like this:
Date of birth: `r Datebirth()`
Let's say that no date of birth has been filled into the data frame. The output on the pdf document looks like this:
- Date of birth: NA
When no Date of birth is filled into the dataframe I want that neither "Date of birth" nor "NA" are printed.
Can someone help?
CodePudding user response:
You should write another function that outputs the whole line:
DOBline <- function() {
DOB <- Datebirth()
if (is.na(DOB)) ""
else paste("* Date of birth: ", DOB, "\n")
}
and then use that in the RMD document.
CodePudding user response:
I would try this "one-line" solution:
`r ifelse(is.na(Datebirth()), "", paste("Date of birth":, Datebirth()))`
This works in a "normal" Rmd file with a "normal variable", but I don't know if it works with a dynamic shiny variable.
