Rmarkdown hyperlink4/6/2023 image_caption - a unique caption for each image.image - the names of images in the document directory (these are basic images I created for this example, displaying A-D).the text variable is used as a hyperlink out to the BCU website.įirst, new elements are added to the input dataframe so that the template can call upon:.the data variable is displayed within a coloured box by adding css to the template.some images are added to the dataset and template.In the example below, the original code is augmented in three ways: You can see from above that four document sections were created automatically from just a few lines of code. # 3: A FOR LOOP ITERATES THROUGH EACH LINE OF THE INPUT DATASET AND PRODUCES 4 SECTIONSĬat(sprintf(template, current$name, current$data, current$text)) Text = replicate(4, paste(sample(x = LETTERS, size = 10, replace = TRUE), collapse = "")), # 1: GENERATE THE DATASET 'INPUT' AND POPULATE WITH RANDOM DATA The code below is marked with the text stages described above. The principle being demonstrated here is that a more complex document can be organised along similar lines, providing that a dataset and template is created in the correct way. Section Title is populated with the contents of name.Next, a template is created for sections within the document.įinally, a for loop iterates across each row within input and populates the template in three places: data: A numerical variable of values between 0 and 1.In the example below, the code first generates a dataset called input comprising four rows of random information populated across three variables: I have then added additional elements to the code in later sections in order to explore document styling and thematic automation. The basis for the work presented here is this post on Stackoverflow, which provided me with the necessary code to produce a basic, working version. Further down, I then add some additional elements to both the database and template in order to create some basic styling, and I then demonstrate how filtering on the dataset could enable the creation of different thematic sections of the resulting document. In the next section, I produce a basic working example of how a dataset and a Markdown template can be used together to produce an HTML document populated by the contents of a database. This post will detail the basics of that exploratory process, and hopefully it will be useful to you if you are considering a similar proejct. In theory this approach seems sound, but I first needed to examine whether I could indeed produce such an outcome. The advantage of approaching the project in this way is that additions and removals of materials related to the initiative need only be added to the database the RMarkdown file can remain untouched. My plan is to achieve this through the creation of an R Markdown file which can be rendered as an HTML page, and my intention is for a database to sit behind that document to power what people see. In a nutshell, the task is to collate a large number of documents from different projects and produce something that will enable readers to easily navigate to reports, videos, links and other material related to their particular area of interest in the initiative. I’m currently working on an internal project at BCU around narrating the progress of a long-term University initiative.
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |