[R] Building Intercative Dashboard using shiny in R

Dheeraj Singh dheeraj2444 at gmail.com
Tue Jul 7 11:30:21 CEST 2015


Hi All,

I have just begun working on shiny package in R and have been building a
dashboard using tutorials and documentation abvailable online. I  am stuck
in the middle.

It would be of great help if you could help me out with my code. I want to
build a dashboard that would take 'date range' and 'variable' to be
displayed as user input and then display the plot. It takes the data from
the csv file.

Currently, the issue is when I change the variable the plot gets changed
but when I change date range, nothing happens to the plot. Please help me
out with this. I have posted the question in stackoverflow as well. Here's
the link: question
<http://stackoverflow.com/questions/31246498/plots-dont-change-with-changing-dates-in-shiny-dashborad-in-r>


Here is the source code:

*ui.R*

library("shiny")
library("shinydashboard")
dashboardPage(

dashboardHeader(title = "Dashboard"),

dashboardSidebar(img(src="jpeg.jpg", length = 75, width = 230),
               dateRangeInput("daterange", "Select Date range:",
                              start = "2014-06-01",
                              end = "2015-06-30"),
               selectInput("var", "Choose a variable to display",
                           choices = c('Total_Orders' = 'Total_Orders',
                                       'Delivered_orders' = 'Delivered_orders',
                                       'Cancelled_orders' = 'Cancelled_orders',
                                       'NEW_USERS_COUNT' = 'NEW_USERS_COUNT'),
                           selected = "Total_Orders")

               ),
dashboardBody(

fluidRow(
  box(title = "plot", status = "primary", solidHeader = TRUE,
      collapsible = TRUE, plotOutput("chart1", height = 250, width = 500))
  )
  ))


*server.R:*

library("shiny")
library("data.table")
file <-     read.csv('filepath.csv', header = TRUE)
setnames(file, old = c('X_id'), new = c('date'))
file$date <- as.Date(strptime(file$date, "%Y-%m-%d" ))

shinyServer(function(input, output)
{output$chart1 <- renderPlot({

               start_date <- input$daterange[1]
               end_date <- input$daterange[2]

               subset(file, date >= start_date & date   <= start_date)

               point <- switch(input$var,
               'Total_Orders' = file$Total_Orders,
               'Cancelled_orders' = file$Cancelled_orders,
               'Delivered_orders' = file$Delivered_ordes,
               'NEW_USERS_COUNT' = file$NEW_USERS_COUNT
               )
               plot(file$date, point, type = "b")
 }) })





​*Sample Data:*

Date        Total_Orders   Delivered_orders   Cancelled_orders
NEW_USERS_COUNT 2015-04-30     23             12               2
           212015-05-01     43             21               12
        322015-05-02     32             13               10
     302015-05-03     43             32               7
  142015-05-04     43             22               3
212015-05-05     32             21               1                  22


​Thanks in advance :)

Thanks!​

	[[alternative HTML version deleted]]



More information about the R-help mailing list