server.R

The server.R in this case is quite simple. First, we load the tidyverse and the data (the data we created in the previous chapter), as shown in the following code: 

library(tidyverse)

load("geocodedData.Rdata")

Then, we define the reactive part of the application, as shown in the following code:

function(input, output) { 

output$plotDisplay <- renderPlot({

gapminder %>%
filter(country == input$country) %>%
ggplot(aes(x = year, y = lifeExp)) +
geom_line()

})

output$outputLink <- renderText({

link = "https://en.wikipedia.org/wiki/"

paste0('<form action="', link, input$country, '">
<input type="submit" value="Go to Wikipedia">
</form>')
})
}

The first part of the code should hold no surprises, being a fairly simple line graph produced using ggplot2. You can see the familiar filter() function being used to restrict the series to data from one country. The second part of the code uses renderText(), which we have used before to show text within an output. The only difference here is that we are going to generate our own HTML. You will recall from the ui.R that this output needs to be wrapped in htmlOutput(), not textOutput(), to preserve the HTML (which would otherwise be automatically escaped in Shiny).

That's a nice gentle introduction to starting to mix HTML into your Shiny applications. Now, let's go to the other extreme and look at building your interface entirely in HTML.

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

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