您好我在R Shiny的TA
包中的chartSeries
quantmod
选项中调用了输入。
这是代码
library(shiny)
library(quantmod)
ui <- fluidPage(
plotOutput("chart", click = "SD1")
)
server <- function(input, output){
df <- reactive(getSymbols("JPM", src = "google", auto.assign = F))
output$chart <- renderPlot(
chartSeries(
df(),
type = "candlesticks",
TA = "addLines(v = input$SD1$x, on = 1)"
)
)
}
shinyApp(ui, server)
返回object 'input' not found
答案 0 :(得分:1)
首先提取点击x <- input$SD1$x
,然后点击paste0
addLine
命令。
library(shiny)
library(quantmod)
ui <- fluidPage(
plotOutput("chart", click = "SD1")
)
server <- function(input, output){
df <- reactive({getSymbols("JPM", src = "google", auto.assign = F)})
output$chart <- renderPlot({
# Extract click
x <- input$SD1$x
# Create addline command
addLineCmd <- paste0("addLines(v = ", x, ", on = 1)")
chartSeries(
df(),
TA = addLineCmd
)
})
}
shinyApp(ui, server)
答案 1 :(得分:1)
出于某种原因,这有效:
{{1}}