Um blog sobre nada

Um conjunto de inutilidades que podem vir a ser úteis


Posted by Diego em Janeiro 13, 2015


Shiny is a platform for creating interactive R programs embedded into a web page. I’ve been playing with it because it is part of the the “Developing Data Products” Coursera course.
This is a tutorial on how to create your first Shiny Application. It is a very simple one that will display n rows on the mtcars dataset.

Initially, it’s necessary to install the Shiny Package:



A “shiny project” is simply a directory that needs to contain at least two files, the user interface (ui.R) where you specify how the application looks and the server (server.R) to controls what it does.

The project is run with the runApp() command. If we try to run it on an empty folder, we’ll get an error message:

> runApp()
Error in shinyAppDir(x): App dir must contain either app.R or server.R.


So what we need to do is to create both files on our working directory (or you can use any directory and its path as a parameter to the function). 

I’ve developed a very simple example that shows n rows of the mtcars dataset and summarizes its results.


This is how the ui.R file looks like:




        headerPanel("Hello Shiny – show me X rows on the mtcars dataset "),



            numericInput("amt", "Number of cars to view:", 5)








And the server.R:





                function(input, output) {

                                ds <- mtcars                      


                                output$myView <- renderTable({

                                                head(ds, n = input$amt)



                                output$summary <- renderPrint({                                          

                                                summary(head(ds, n = input$amt))





See that the variables amt, myView and summary are the communication variables between both “layers” (UI and Server). Calling runApp() will start the application:

> runApp()
Listening on

Distribution Shiny Apps:


A web App is not useful if you can’t distribute it. There are 2 main ways you can do that, using Shiny Server or a website like Shiny Apps.  Shiny Server runs on Linux only and I won’t be covering it here but all the information you need can be found on this link:

If you want to deploy your app to the web, Shiny Apps ( is a great option. Just go to the website, create an account and run the commands found here ( on your R studio to install it.



Once you do it, all you have to do is call the deploy apss command and a browser will open with the application deployed:


> shinyapps::deployApp("c:\\git\\ShinyEx")

Preparing to deploy application…DONE

Uploading application bundle…DONE

Deploying application: 28469…

Waiting for task: 4160268

  building: Building image: 109550

  building: Installing packages

  building: Installing files

  building: Pushing image: 109550

  deploying: Starting instances

  rollforward: Activating new instances

  success: Stopping old instances

Application successfully deployed to


This particular example can be found here:  



2 Respostas to “Shiny”

  1. Continue sempre ajudando com esse ótimo trabalho, achei interessante o seu post.

    Por acaso, você tem ideia de criar um tópico sobre esse
    mesmo tema só que um pouco mais detalhado? Já está compartilhado e recomendado!
    Bom trabalho!

Deixe uma Resposta

Preencha os seus detalhes abaixo ou clique num ícone para iniciar sessão:

Logótipo da

Está a comentar usando a sua conta Terminar Sessão /  Alterar )

Google+ photo

Está a comentar usando a sua conta Google+ Terminar Sessão /  Alterar )

Imagem do Twitter

Está a comentar usando a sua conta Twitter Terminar Sessão /  Alterar )

Facebook photo

Está a comentar usando a sua conta Facebook Terminar Sessão /  Alterar )


Connecting to %s

%d bloggers like this: