2017-02-16 10 views
0

chart_Seriesと色付きラインを表示すると、shinyとスライダの使用に関する問題があります。スライダを右側から使用しているときは、色が適切に選択されます(主に赤い点)。スライダを左側に使用すると(最新のデータを見るなど)、色は適切に選択されません(緑色にする必要があります)。私は助けを求めており、私は助言に感謝しています! 、私の知る限りR光沢のある量子ドットズームチャートと固定したカラーリング

shinyは、(それぞれのかなり論理的に...)着色ベクトルデータを編集しませんが。

require(quantmod) 
require(shiny) 
getSymbols("YHOO") 
data <- YHOO 
data <- data[1:100,] 

col_function <- rep("red",50) 
col_function <- c(col_function, rep("green",50)) 


plot <- { 

    date_range <- index(data) 


    if (interactive()) { 
    options(device.ask.default = FALSE) 
    # Define UI 
    ui <- fluidPage(
     titlePanel("Time:"), 
     sidebarLayout(
     # Sidebar with a slider input 
     wellPanel(
      tags$style(type="text/css", '#leftSlide { width:200px; float:left;}'), 
      id = "leftSlide", 
      sliderInput("Range", "Choose Date Range:", 
         min = first(date_range), max = last(date_range), value = c(first(date_range),last(date_range))) 
     ), 

     mainPanel(
      plotOutput("Plot", width = "150%", height = "500px") 
     ) 
    ) 
    ) 

    # Server logic 
    server <- function(input, output) { 
     output$range <- renderPrint({ input$slider2 }) 
     output$Plot <- renderPlot({ 

     x_ti2 <- xts(rep(1, NROW(data)), order.by = index(data)) 
     x_ti2[1, ] <- 0.5 

     chart_Series(data) 
     add_TA(x_ti2, col = col_function, pch = 9, type = 'p', cex = .7) 
# Another way below, but the color function is still not working 
     #chart_Series(data["2017"], TA = 'add_TA(x_ti, col = col_function, pch = 15, type = "p", cex = .7); add_TA(x_ti2, col = "orange", pch = 9, type = "p", cex = .7)') 

     zoom_Chart(paste(input$Range, collapse = "::")) 
     }) 

     observe({ 
     print(input$Range) 
     }) 
    } 

    shinyApp(ui, server) 
    } 
} 

plot 
+0

私はchartSeriesとchart_seriesを見てきました。どちらも同じ問題を抱えているようです。私の見解では、プロットのズームは、尖った線を制御しません。あたかもchartSeriesとは独立しているようです。しかし、これは依然として相手側からの正確なズーミングの理由を説明していない。さらに、私はdateRangeInputをテストしました。同じ問題が発生しました。 – Simon

答えて

0

だから、私は私自身の問題の回避策を見つけました。したがって、あなたは着色の範囲を更新するように光沢を伝える必要があります。

まず、私は着色結果をxpsオブジェクトに変換しました。次に、元のデータ行列にx_ti2変数を追加し、col_functionの入力$ rangeで変数を定義しました。変数は、地球環境の一部である必要があります(shinyが使用できるように)。私は誰かが似たような問題を抱えている場合、これがいくつかの問題を解決することを望みます。

関連する問題