【发布时间】:2021-01-31 19:57:44
【问题描述】:
我希望通过选择每个列表的名称从 xts 系列列表中绘制 xts。 我不理解反应性和列表选择的工作原理
library(zoo)
library(dygraphs)
library(xts)
d <- seq(as.Date("2020/01/01"), as.Date("2020/05/01"), "months")
xts1 <- xts(rnorm(5),order.by = d)
xts2 <- xts(rnorm(5),order.by = d)
xts3 <- xts(rnorm(5),order.by = d)
l <- list(xts1,xts2,xts3)
names(l) <- c("uno","dos","tres")
创建 xts 对象列表
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("Old Faithful Geyser Data"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(
selectInput(names,names,names(l))
),
# Show a plot of the generated distribution
mainPanel(
dygraphOutput("plot")
)
)
)
# Define server logic required to draw a histogram
server <- function(input, output) {
#option 1
p <- reactive({
input$names
})
output$plot <- renderDygraph({
l[[p]]
})
# option 2
output$plot <- renderDygraph({
l[[input$names]]
})
}
# Run the application
shinyApp(ui = ui, server = server)
这两种方式都行不通。 欣赏:)
【问题讨论】:
标签: r shiny dygraphs shiny-reactivity