简体   繁体   English

R闪亮的动态数据功能 - 如何根据日期范围输入更改访问哪个CSV?

[英]R shiny dynamic data function - how to change which CSV is accessed depending on date range input?

I would like to have a dashboard that allows you to select certain dates, and depending on those dates have the corresponding CSV file accessed to change my output plot.我想要一个仪表板,允许您选择某些日期,并根据这些日期访问相应的 CSV 文件以更改我的输出图。 In order to do this, do my CSVs need to be on a public site and use the getSymbols function?为了做到这一点,我的 CSV 是否需要在公共站点上并使用 getSymbols 函数? I already have the correct input and output structure, I'm just trying to figure out dynamic data set access.我已经有了正确的输入和输出结构,我只是想弄清楚动态数据集访问。 Any advice is helpful!任何建议都有帮助!

There is no need to put your data on public site.无需将您的数据放在公共站点上。 shinyapps.io allows to store your data in your application folder. Shinyapps.io允许将您的数据存储在您的应用程序文件夹中。 Please see the code which automatically loads csv-file depends on data input:请参阅根据数据输入自动加载 csv 文件的代码:

# csv file simulation
set.seed(123)
write.csv(data.frame(x = rnorm(100), y = rnorm(100)), "old.csv")
write.csv(data.frame(x = 100 * rnorm(100), y = 100 * rnorm(100)), "new.csv")



library(shiny)

# Define UI for application 
ui <- fluidPage(

   # Application title
   titlePanel("Dynamic loading of csv file"),

   sidebarLayout(
      sidebarPanel(
        radioButtons("rb", "Choose one:",
                     choiceNames = list(
                       "old", "new"),
                     choiceValues = list(
                       2, 1
                     ))
      ),

      mainPanel(
         plotOutput("distPlot")
      )
   )
)

server <- function(input, output) {
   output$distPlot <- renderPlot({
     if(input$rb == 1) {
       df <- read.csv("new.csv", header = TRUE)
       clr <- "red"
     } else {
       df <- read.csv("old.csv", header = TRUE)
       clr <- "blue"
     }

      plot(df$x, df$y, col = clr)
   })
}

# Run the application 
shinyApp(ui = ui, server = server)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM