0
我有一個問題,關於shiny
和使用滑塊,當顯示chart_Series
和彩色線條。從右側使用滑塊時,適當選擇顏色(主要是紅點)。當我使用左側滑塊(例如查看最新數據)時,顏色選擇不當(應爲綠色)。我尋求幫助,我很感謝您的任何建議!R Shiny quantmod zoomChart和固定着色的點
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
我已經看過chartSeries以及chart_series。兩者似乎都有相同的問題。從我的角度來看,情節的縮放並不能控制尖銳的線條。看起來好像它們獨立於chartSeries。但是,這仍然不能解釋從另一側正確放大的原因。此外,我測試了dateRangeInput:發生了同樣的問題。 – Simon