Ideas based on WorldPhones example

64 views
Skip to first unread message

Bjenk Ellefsen

unread,
Sep 28, 2014, 7:37:11 AM9/28/14
to shiny-...@googlegroups.com
I'm trying to wrap my head around shiny to start developing interactive charts and maybe eventually design a dashboard using bootsrap and shiny.

I'm trying to adapt the telephones by region example to understand the calls to buttons and such. Telephones by region

What I'm trying to do is to have two buttons on the left: the first one selects a state, the second one a month.
The bar graph to be shown is always the state and country together for comparison. The call with the button for state is something I dont fully understand.

My data can be in one table or multiple tables, it doesnt matter. Here's a fictirioius example

Geography    characteristics    month1    month2
Country         Urate                    7            7.5
Country         EmpRate               67         68
Country         PartRate                61         62
State1           Urate                     8           7.5         
State1           EmpRate               65         66
State1           PartRate               60          59
State2           Urate                    10          9         

Now, the r code to generate the graphs is not the issue. I work with R but shiny is something new to me.

Any insights would be greatly appreciated. Below I have included my current code (not properly working bcode in development).

# Define the overall UI
shinyUI
(
 
 
# Use a fluid Bootstrap layout
  fluidPage
(    
   
   
# Give the page a title
    titlePanel
("LFA by State"),
   
   
# Generate a row with a sidebar
    sidebarLayout
(      
     
     
# Define the sidebar with one input
      sidebarPanel
(
        selectInput
("Geography", "State:",
                    choices
=colnames(StateLFA)),
        hr
(),
        helpText
("Data from Census 2011")
     
),
     
     
# Create a spot for the barplot
      mainPanel
(
        plotOutput
("LFAPlot")  
     
)
     
   
)
 
)
)

Server:
StateLFA <- read.csv("table.csv")

# Define a server for the Shiny app
shinyServer
(function(input, output) {
 
 
# Fill in the spot we created for a plot
  output$LFAPlot
<- renderPlot({
   
   
# Render a barplot
   
    ggplot
(ProvLFA, aes(x=characteristics, y=value, fill=Geography)) +
        geom_bar
(position = "dodge", stat="identity") +
        theme_classic
() +
        theme
(axis.text.x = element_text(vjust=0.5, size=15),
            axis
.text.y = element_text(vjust=0.5, size=15)) +
        theme
(panel.border = element_blank()) +
        theme
(legend.text=element_text(size=16)) +
        theme
(legend.position="bottom") +
        theme
(axis.title.x=element_text(size=15)) +
        theme
(plot.background=element_rect(fill = "transparent",
            colour
= NA)) +
        scale_fill_brewer
(palette="Paired") +
        ylab
("") + xlab("") +
        guides
(fill=guide_legend(title=NULL)) +
        ggtitle
("\n") +
        geom_text
(aes(label=Percent), vjust=-0.5, position=position_dodge(width=0.9))    
           
       
#Percent label can be white and inside the bar
       
#geom_text(aes(label=Percent), vjust=1, colour="white",
           
#position=position_dodge(width=0.9))

 
})
})



Abhinav Agrawal

unread,
Sep 29, 2014, 10:13:18 PM9/29/14
to shiny-...@googlegroups.com
Not sure if I understand what you are looking for…are you looking 2 add two buttons and have some kind of control to your app using the buttons or you want to add something like 2 drop downs where one drop down allows to select the country…the second month? Please clarify..

Adding some youtube tutorial videos on shiny in case it helps...

Reply all
Reply to author
Forward
0 new messages