Description
Prerequisites
To use script, you should:
- – Have basic knowledge of the language R and Shiny
- – Create an account on the free tool shinyapps.io or you choose a different hosting method: http://shiny.rstudio.com/deploy/
- – Have on your computer RStudio https://www.rstudio.com/
- – Host your script from RStudio with your desired hosting method: http://shiny.rstudio.com/tutorial/
REST URL creation
The script works with AT Internet’s REST URL. Your API call must contain all of the following dimensions and metrics:
- – Pages (Pages)
- – URL (Site Custom Variables) or d_ati_url (Option)
- – Visits
You may use further Dimensions and/or Metrics. Please be sure to adapt the script if you enrich the REST URL.
The script works with an API-key. You can create REST URLs with API-keys in the
Be sure that your REST URL uses HTML format.
Your final REST URL should look like this:
https://apirest.atinternet-solutions.com/data/v2/html/getData?&columns={d_page,d_ati_url,m_visits}&sort={-m_visits}&space={s:#LEVEL1ID#}&period={R:{D:’-1′}}&max-results=10000&page-num=1&apikey=#APIKEY#
The example code uses “yesterday” as period.
Feel free to use your desired period from the Data Query interface or directly from our documentation: https://developers.atinternet-solutions.com/rest-api-en/response-structure-parameters-rest-en/period-parameter-rest-en/.
If your URL variable starts with “www.” you need to make a little change in the script at the “href” step.
Script set up
Your script must contain two parts.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
### CLICKABLE URLS ### # Create user interface: # Control the layout, appearance, Widgets that capture user inputs. # Also, displays the output, for instance the title, page layout, text input, radio buttons, drop down menus, graphs, etc. library(shiny) library(shinyjs) library(V8) shinyUI(fluidPage( # Application Title titlePanel("Clickable Pagenames"), # Layout of the sidebar # 1. Sidebar Panel: Input from the User sidebarLayout( sidebarPanel( h2("Information"), p("Just click on a Pagename to get access to the content directly on your side in a new tab") ), # 2. Main Panel: Output for the User mainPanel( h4("Table"), dataTableOutput("df") ) ) )) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
### CLICKABLE URLS ### # Set of instructions that uses the input provided by the user, # process them and produces the required output which is further displayed by ui.r script. library(shiny) library(shinyjs) library(V8) library(ggplot2) library(RCurl) library(XML) library(stringr) library(plyr) library(tidyr) library(httr) shinyServer( function(input, output, session){ #### A.) INPUT: HERE COMES THE R SCRIPT WHICH DOES ALL THE MAGIC #### ### I. SCRIPT START ### ## LOAD DATA START ## # Load REST URL df <- readHTMLTable(getURL("https://apirest.atinternet-solutions.com/data/v2/html/getData?&columns={d_page,d_ati_url,m_visits}&sort={-m_visits}&space={s:#LEVEL1ID#}&period={R:{D:'-1'}}&max-results=10000&page-num=1&apikey=#APIKEY#"), stringAsFactors = FALSE, header = TRUE, which = 1, colClasses = c("character","character","integer")) ## LOAD DATA END ## ## MANIPULATE DATAFRAME START ## df$Pagename <- paste0("<a href=",df$URL, "' target='_blank'>",df[,1],"</a>") df <- subset(df,select=c(4,3)) ## MANIPULATE DATAFRAME END ## ### I. SCRIPT END ### #### B.) OUTPUT: HERE YOU DECLARE ALL THE OUTPUTS YOU WANT TO CALL in ui.R #### # 1. HTML TABLE output$df <- renderDataTable(df, escape = FALSE) } ) |
Finally, you can run your app and publish it to shinyapps.io or your favorite hosting system.
Tip: If you want, you can integrate your shiny application in one of your AT Internet dashboards as an iframe with a Text Box:
<p><iframe src=”https://atinternet.shinyapps.io/#YOUR APP#/” width=”2000″ height=”1100″ frameborder=”0″ allowfullscreen=”true”></iframe></p>
Please note that your application is independent from any setting in the dashboard module.
Reviews
There are no reviews yet.