A Shiny example – SAP HANA, R and Shiny

[This article was first published on Blag's bag of rants, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

As you may already know…I love R…a fancy, open source statistics programming language. So today, I decided to learn something new using R.

There aren’t much Web Servers for R, but there’s one that I really like called Rook, that I covered on my blog RSAP, Rook and ERP.

Today, I tried a new one that’s is making a lot of noise in the R community, called Shiny. I gotta say…I felt instantly in love with it…

So you may ask…so what’s so cool about Shiny? Well…besides the fact that it allows you to create web applications using R…it’s completely dynamic…meaning that once you change a parameter, the graphic and not the whole web page is reloaded automatically…awesome, huh?

So…when I wrote about Ruby and SAP in my blog Ruby joins the SAP HANA party, I tried to emulate an SE16 to browse tables from the SFLIGHT package…this time…I will do the same but with a little twist…the application will allow you to choose a table, but also to choose how many records you want to display…

So, what we need? Simply…if you haven’t already…install this two packages…”shiny” and “RODBC”…

After this, we need to create a folder called Shiny and after this create a new one called SAP_HANA_R (This is just to be organized).

We now need to create two files, called ui.R and server.R

odbcQuery(ch,"SELECT table_name from SYS.CS_TABLES_ where schema_name = 'SFLIGHT'")
  headerPanel("SAP HANA and R using Shiny"),
    selectInput("Table", "Choose a table:",
                choices = tables$TABLE_NAME),
    numericInput("Records", "Number of Records to view:", 10)

shinyServer(function(input, output) {
  output$view <- reactiveTable(function() {
    query<-paste("SELECT TOP",input$Records,"* FROM",schema_table)
    head(result, n = input$Records)

When we have finished with the two files...we can create a new one just to call our application.


Keep in mind that the setwd("C:/Blag/R_Scripts") is my main R Script folder, as setwd stands for "Set Working Directory"...

When we run Shiny_HANA.R, the browser will popup showing the parameters and the table by default.

As you can see, we can choose a new table to display.

We can also choose how many lines or records we want to display...

I hope you like it... -:)



To leave a comment for the author, please follow the link and comment on their blog: Blag's bag of rants.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)