Adding HTML using the tag() function

Shiny provides a helper function to use basic HTML tags to create your application. However, if there are some HTML tags that are not included in the function, we can use the tag function. To find out about the tag function, you can simply type names (tags) in the console. This will give you all the functions that are available, as seen in the following screenshot:

To use the function, we can simply use tags$name, where the name is the function required. The name argument becomes the argument within the HTML tag. As you can see in the following screenshot, the first example, tags$script, will yield an output of the script html tag followed by the named argument type. The arguments that do not have names are used as the body of the tag. As seen in the second example, the named argument becomes href, whereas the unamed argument, This is an example, becomes the body of the HTML tag:

As seen in the previous example, the unnamed arguments are used as the body of the tags. We can use this to nest tags. Let's consider the following example:

Here, we are using tags$head and we are using a series of other tags separated by commas. In the example, we are using the links that we added at the beginning of the HTML Shiny UI definition that we created in the previous section. The output is the following HTML with the title, scripts, and style sheet all nested within the head section:

There may be some arguments that contain characters that can affect the output in R. In such cases, we will use backticks (`) around the text.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset