0

I plot my data set using this code :

  activity <- unlist(dActivityProbe$value)
> tail(activity,10)
 [1] "high" "high" "high" "high" "high" "low"  "high" "none" "none" "none"
> head(dActivityProbe$time,10)
      timestamp 
 [1,] 1406613553
 [2,] 1406613585
 [3,] 1406613586
 [4,] 1406613706
 [5,] 1406613706
 [6,] 1406613825
 [7,] 1406613826
 [8,] 1406613945
 [9,] 1406613947
[10,] 1406614065
> date_time <- as.POSIXlt(as.numeric(dActivityProbe$time), origin="1970-01-01", tz = "GMT")
> head(date_time,10)
 [1] "2014-07-29 05:59:12 GMT" "2014-07-29 05:59:45 GMT" "2014-07-29 05:59:46 GMT" "2014-07-29 06:01:45 GMT"
 [5] "2014-07-29 06:01:46 GMT" "2014-07-29 06:03:45 GMT" "2014-07-29 06:03:45 GMT" "2014-07-29 06:05:45 GMT"
 [9] "2014-07-29 06:05:46 GMT" "2014-07-29 06:07:44 GMT"
> p <- qplot(data=dActivityProbe,,color=activity,x=date_time,y=activity)
> print(p)

And it's success for generating plot like this image enter image description here

But the problem is, when I tried to move this code into shiny, I got error.

The error look like this In R console :

Warning in as.POSIXlt(as.numeric(dActivityProbe$time), origin = "1970-01-01",  :
  NAs introduced by coercion
Error in seq.int(0, to0 - from, by) : 'to' cannot be NA, NaN or infinite

In shiny web :

'to' cannot be NA, NaN or infinite

Shiny Apps :

ui.R

  tabPanel("Time Series",
                                              titlePanel("Time Series Activity Probe Plot"),
                                              mainPanel(
                                                   plotOutput("Activity_time_series")
                                              )

dActivityProbe :

 head(dActivityProbe)
        time value
1 1406613553  none
2 1406613585  none
3 1406613586  none
4 1406613706  none
5 1406613706  none
6 1406613825  none

server.R

    library(shiny)
    library("RSQLite")
    library("rjson")
    library("ggplot2")
    library("scales")


    activity <- unlist(dActivityProbe$value)
    date_time <- as.POSIXlt(as.numeric(dActivityProbe$time), origin="1970-01-01", tz = "GMT")

shinyServer(function(input, output) {

         output$Activity_time_series <- renderPlot({
          p <- qplot(data=dActivityProbe,,color=activity,x=date_time,y=activity)
          print(p)

     })

Thank you for helping

user46543
  • 1,033
  • 4
  • 13
  • 23
  • Can you post a reproducible example for the Shiny app? – shadowtalker Aug 05 '14 at 02:56
  • Are you sure you've read the data in correctly on the shiny side? Your shiny code isn't exactly complete. It would be better to make a fully [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick Aug 05 '14 at 03:27
  • @MrFlick I already add again, actually my shiny apps contain many functions and it's work well only this one, I don't know, i tried in console work well but in shiny not. thank you, – user46543 Aug 05 '14 at 03:36
  • The code is still not reproducible. There is no call to `shinyServer` and right now there are a pair of un-opened bracket and parenthesis on the last time. In order to be complete, It should be something we can copy and paste in order to run (with minimal, if any, alterations). It is not clear where `dActivityProbe` comes from or what it's exact structure is. Please read the suggestions in the previous link I included on how to include sample data. – MrFlick Aug 05 '14 at 03:40

1 Answers1

1

I tried to re-create your problem, however there were no issues and no bugs. The data were simulated and permutation was used in order to look realistic.
Are you sure there are not missing values in your code? Another possible issue could be that you are not reading the data in the server? Last but not least have you checked all your parenthesis?

Here is the code:

runApp(

  list(

    ui = {
      tabPanel("Time Series",
               titlePanel("Time Series Activity Probe Plot"),
               mainPanel(
                 plotOutput("Activity_time_series")
               )
      )         
    },


    server = {
      library(shiny)
      library("RSQLite")
      library("rjson")
      library("ggplot2")
      library("scales")

      ##Similate the data
      similate<-function(n){
        value<-sample(c("high","low" ,"none"),n,replace=TRUE)
        time<-c(1406613553, 1406613585, 1406613586, 1406613706, 1406613706, 1406613825, 1406613826, 1406613945, 1406613947, 1406614065)
        time_base<-(sapply(time,function(x) as.numeric(unlist(strsplit(toString(x),'')))))
        time<-apply(apply(time_base,1,function(x ) sample(x,n,replace=TRUE)),1,function(x) as.numeric(gsub(", ",'',toString(x))))
        return(data.frame(time=time,value=value))
      }

      dActivityProbe <-similate(1000)

      activity <- unlist(dActivityProbe$value)
      date_time <- as.POSIXlt(as.numeric(dActivityProbe$time), origin="1970-01-01", tz = "GMT")

      shinyServer(function(input, output) {

        output$Activity_time_series <- renderPlot({
          p <- qplot(data=dActivityProbe,,color=activity,x=date_time,y=activity)
          print(p)

        })
      }
      )
    }

  )
)

Kind Regards,

Stanislav
  • 2,629
  • 1
  • 29
  • 38