2016-10-30 13 views
2

私のコードでは、(2つのオプションが選択されているときに)グラフ上に2つの線があり、X軸が時間であるような光沢のあるアプリケーションを作成しない理由を説明できますか?これは、グラフ上に1行しか許可しないと正しく動作するようです。複数の線を光沢で塗りつぶす

あなたが例えば... do.call周り tsを削除する必要が
#rm(list=ls()) 
library(shiny) 
library(jsonlite) 
library(dygraphs) 
library(xts) 
library(dplyr) 
library(readr) 

item.ids<-read_fwf('http://eve-files.com/chribba/typeid.txt',fwf_empty('http://eve-files.com/chribba/typeid.txt',skip = 2,col_names = c('typeID', 'typeName')),skip = 19) 
item.ids$typeID<-as.numeric(item.ids$typeID) 

ui<-fluidPage(
    titlePanel("EVE Mineral Price Graph"), 

    sidebarLayout(
    sidebarPanel(
     helpText("EVE Mineral Price Graph"), 

     #restricted to comparing 2 things because of dygraph 
     selectizeInput('var.name', label = NULL, choices = item.ids$typeName, multiple=T,selected=item.ids$typeName[1],options = list(maxItems = 2,maxOptions=5)), 

     selectInput("var.col", 
        label = "Choose a variable to display", 
        choices = c("lowPrice","avgPrice","highPrice","volume","orders"), 
        selected = "lowPrice") 
    ), 
    mainPanel(dygraphOutput("map")) 
)) 

########################################################################################## 

server<-shinyServer(
    function(input, output) { 

    getColumn<-reactive({ 
###this lapply takes in the var name from the text input, converts it to a number, retrieves the data from a website then returns the time series.  
     ans<-lapply(input$var.name,function(x){ 
     item.id<-item.ids$typeID[which(item.ids$typeName==x)] #user chedked text name, this converts to number 
     eve.url<-paste0("http://eve-marketdata.com/api/item_history2.json?char_name=demo&region_ids=10000002&type_ids=",item.id,"&days=100") 
     eve.data<-data.frame(fromJSON(txt=eve.url))$emd.row 
     eve.data$date<-as.Date(eve.data$date) 
     data<-as.vector(as.numeric(eve.data[,input$var.col])) 
     xxx<-xts(data,order.by=eve.data$date) 
     colnames(xxx)<-x 
     xxx 
     }) 
     ts(do.call(cbind, ans)) 
    }) 

    output$map <- renderDygraph({ 
     data<-getColumn() 
     browser() 
     #plot(stl(data, s.window="periodic")) 
     #plot(decompose(data))  
     #plot(data) 
     dygraph(data, main="Mineral Graph",xlab="day",ylab="item price") %>% dyRangeSelector() 
    }) 
    } 
) 

##### 
shinyApp(ui, server) 

答えて

0

server <- shinyServer(function(input, output) { 
    getColumn <- reactive({ 
    ###this lapply takes in the var name from the text input, converts it to a number, retrieves the data from a website then returns the time series. 
    ans <- lapply(input$var.name, function(x) { 
     item.id <- 
     item.ids$typeID[which(item.ids$typeName == x)] #user chedked text name, this converts to number 
     eve.url <- paste0(
     "http://eve-marketdata.com/api/item_history2.json?char_name=demo&region_ids=10000002&type_ids=", 
     item.id, 
     "&days=100" 
    ) 
     eve.data <- data.frame(fromJSON(txt = eve.url))$emd.row 
     eve.data$date <- as.Date(eve.data$date) 
     data <- as.vector(as.numeric(eve.data[, input$var.col])) 
     xxx <- xts(data, order.by = eve.data$date) 
     colnames(xxx) <- x 
     xxx 
    }) 
    do.call(cbind, ans) 
    }) 

    output$map <- renderDygraph({ 
    data <- getColumn() 
    # browser() 
    #plot(stl(data, s.window="periodic")) 
    #plot(decompose(data)) 
    #plot(data) 
    dygraph(data, 
      main = "Mineral Graph", 
      xlab = "day", 
      ylab = "item price") %>% dyRangeSelector() 
    }) 
}) 
関連する問題