
(You will need the shiny package and the shiny incubator package)
1. Make a hit counter
The hit counter is easily made with the following code in the server.R file:
SP <- list() # Server parameters
# Record the number of poeple who have used the app
# since initiation on the server
SP$npers <- 0
shinyServer(function(input, output) {
# shinyServer is Started up every time the domain is called.
# Use <<- to assign to the global server environment.
SP$npers <<- SP$npers+1
...
}
# ui.R
...
With the ui.R file there is a single function at the appropriate place:
# Display the total number of hits on the app.
h5(textOutput("hits")),
...
2. Allow for three panels in the user interface. In order to accomplish this I simply modified the pageWithSidebar function replacing 'div(class = "row-fluid", sidebarPanel, mainPanel)' with 'div(class = "row-fluid", left, middle, right)'. I tried to write a function that more generally took ... but could not figure out the exactly right syntax. See where the new function is defined below:
# This is a UI page with three panels
threepage <- function(headerPanel,left,middle,right) {
bootstrapPage(div(class = "container-fluid", div(class = "row-fluid",
headerPanel), div(class = "row-fluid", left, middle, right)))}
3. Insert an HTML break and an external link. Both of these things are extremely easy. For many HTML tags there are already programmed up shiny functions which handle them. However, there are quite a few so not all of them have a function associated with it. A typical HTML function is br which returns:
> br()
[1] "<br/>"
attr(,"html")
[1] TRUE
if called. In terms of HTML this command will insert a line break. If you are interested in including HTML in which there is no function already programmed you can use the function HTML
>HTML"<hr/>"
[1] "<hr>"
attr(,"html")
[1] TRUE
In order to insert a link into shiny you could either use the HTML"<a href=>..." type html sequence or one could use the built in functions.
a(Text, href="link.com")
Personally I prefer the built in function because they are very appealing and concise for an R programmer.
Take a look at the app at:
![]() |
App Link |
No comments:
Post a Comment