Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Dashboard Development with Shiny

You're reading from   Hands-On Dashboard Development with Shiny A practical guide to building effective web applications and dashboards

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher Packt
ISBN-13 9781789611557
Length 76 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Chris Beeley Chris Beeley
Author Profile Icon Chris Beeley
Chris Beeley
Arrow right icon
View More author details
Toc

Shiny functions to produce HTML

Shiny is based on HTML and hence it allows you to write an entire interface in R and Shiny without thinking of HTML. You can also update your interface using Shiny built-in functions or add custom HTML using the tag function. Shiny also allows you to write an entire interface using HTML from scratch. To work on a Shiny application for the first time, it is preferable that you are familiar with HTML and CSS.

The following are a few common HTML tags:

  • p: This is used to create a paragraph
  • h1-h6: Heading style used to add headings and subheadings, where h1 is considered to be the largest and h6 the smallest
  • a: This is used to create links and it is associated with href, which is the address to the web page. For example, href = http://shiny.rstudio.com/articles/, "Shiny docs", where href is used to define the link and the following text is used to display the text to the user
  • br(): This is used to create a line break
  • div: This tag is used to define a section with a particular style, defined in the same way as we use a div tag in HTML
  • span: The span tag is used to define a similar style to a string of text
  • pre: This is used for format code sections or commands in block quotes or pre-formatted text
  • code: We can also use the code tag if you want the code block to look the same as computer code
  • img: The img tag is used to define the image
  • strong: This is used to set the text in bold format
  • em: The em tag is used to style the text in italics format or to emphasize the text
  • hr: This is used to add a horizontal line between text

The following screenshot shows the use of some of the HTML tags:

Let's have a look at the code for the application present in the ui.r file:

mainPanel( 
    tabsetPanel( 
        tabPanel("Budgets over time", plotOutput("budgetYear"), 
            p("For more information about ", strong("Shiny"), " look at the ", 
            a(href = "http://shiny.rstudio.com/articles/", 
"documentation.")), hr(), h3("Some code goes under here"), p("If you wish to write some code you may like to use the pre()
function like this:", pre('sliderInput("year", "Year", min = 1893, max = 2005, value = c(1945, 2005), sep = "")'))), tabPanel("Movie picker", tableOutput("moviePicker")) ) )

As we can see in the code block, we have used a strong tag to add bold text within the p function within the same paragraph. We have also used href for the link, hr for the horizontal line, and the pre tag for the code block in the same application.

You have been reading a chapter from
Hands-On Dashboard Development with Shiny
Published in: Aug 2018
Publisher: Packt
ISBN-13: 9781789611557
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image