Ex 10 Vis

URL Shiny

 https://danno.shinyapps.io/Ex10a/
 

URL Rpubs

 http://rpubs.com/fast_Eddie/433450
 
 

Objective

Build A Property Market Dashboard Your goal is to build a basic property market dashboard using the txhousing dataset. Keep it simple. The dashboard should include at least three panels.

Unfortunetly, I ran out of time, in my case I have one panel with three choices

#   Pre Process and Extract Section / columns / 


txhousing <-  as.data.frame(ggplot2::txhousing)
txhousing <- na.omit(txhousing)
#head(txhousing)

txhousing$year <- as.numeric(txhousing$year)
txhousing$sales <- as.numeric(txhousing$sales)
txhousing$month <- as.numeric(txhousing$month)
#str(txhousing)
#summary(txhousing)       ##  <<==    check this and rechoose columns

txh1 <-  txhousing  %>%  group_by(date) %>% arrange(city)
txh1 <-  txh1 %>% subset(txh1$year >= '2007')

# txh2 <-  txh1 %>% subset(txh1$sales >= '300' & txh1$sales <='499')
# txh2 <- txh2[-c(5,6,8)]
#str(txh2)
txh1$volume <-  round(txh1$volume / 10000, 0)
#head(txh1)
txh3 <-  txh1 %>% subset(txh1$sales > '600' & txh1$sales <'900') 
#head(txh3)
txh3 <- txh3[-c(5,6,8,9)]
txh3 <- as.data.frame(txh3)

txh3 <- txh3 %>% group_by(city) %>% arrange(year)
txh3 <- txh3[-c(2)]  
  
# txh3$city <- sort(txh3$city)
#class(txh3)
#head(txh3)
#str(txh3)
#summary(txh3)
# Define a function to remove the values outside the limits

remove_outliers <- function(x, na.rm = TRUE, ...) {
  qnt <- quantile(x, probs=c(.25, .75), na.rm = na.rm, ...)
  H <- 1.5 * IQR(x, na.rm = na.rm)
  y <- x
  y[x < (qnt[1] - H)] <- NA
  y[x > (qnt[2] + H)] <- NA
  y
}

txh3$sales <- as.numeric(remove_outliers(txh3$sales)) 
txh3 <- na.omit(txh3)

#str(txh3)
summary(txh3)
##      city               month            sales          listings      
##  Length:851         Min.   : 1.000   Min.   :  9.0   Min.   :   99.0  
##  Class :character   1st Qu.: 3.000   1st Qu.: 73.0   1st Qu.:  615.5  
##  Mode  :character   Median : 6.000   Median : 84.0   Median :  882.0  
##                     Mean   : 6.417   Mean   :307.3   Mean   : 1718.9  
##                     3rd Qu.:10.000   3rd Qu.:669.5   3rd Qu.: 2556.5  
##                     Max.   :12.000   Max.   :898.0   Max.   :12349.0
## Single file Shiny app.R ------------------ working 

# Assign server function

##  choose city , sales , listings   which is   chr, dbl , dbl
    
server <- function(input, output) {

 
   output$Plot2 <- renderPlot({
    ggplot(data = txh3, aes(x = city, y = get(input$var2))) +     #FF0099  #999999
       geom_boxplot( colour="#56B4E9") +
       labs(y = input$var) +
       theme(axis.text.x=element_text(angle=45,hjust=1, size = 12)) +
       theme(axis.text.y=element_text(hjust=1, size = 12))
        # xlab("City") +
        # ylab("")
       #theme_bw(base_size=12)
       #theme(legend.text=element_text(size=20)) +
  
   })


}

# Create ui

ui <- fluidPage(
  titlePanel("Sales for all Regions / Cities"),
  sidebarLayout(
    sidebarPanel(

      selectInput("var2", " ", 
                  colnames(txh3[2:4]),  
                  selected = colnames(txh3[4])),
      
 
      HTML(
                       #'<br/>',  ##  br/ is html \n equivalent ##  h1-6 is text height
      paste('<br/>',
      h2("Years    :: 2007 - 2015 ::    \n"),'<br/>', 
      #h3(" \n") , '<br/>',                       
      h3("Month = Total sales per month \n"),  #'<br/>' ,  
      h4("       (min, median, max) \n"),   #'<br/>' ,
      h3("Sales = Total Sales per City  \n"),
      h4("       (min, median, max)    \n"),
      h3("Listings = Total Listings per City     "),  
      h3("   \n")
      ))
      ),
               
 
    mainPanel(plotOutput("Plot2",  height = "650px") #height=350
                             )))
              

## Deploy app

shinyApp(ui = ui, server = server )  ## this below code corrected from half page to full page
Shiny applications not supported in static R Markdown documents
#shinyApp(ui = ui, server = server, options = list(height = 1080)) ## needed this for the deploy

Conclusion

Not exactly what I had in mind , a lot more could have been displayed , I consider this to be basic .