基于选定的单选按钮选项,在闪亮的R中单击提交按钮后如何显示图表和数据?

问题描述 投票:0回答:1

我开发了一个仪表板来显示我正在运行的问题的虚拟示例。闪亮的仪表板有四个框。前两个框使用非季节性有马模型显示了绘图图表和预测数据。底部的两个框显示了使用季节性Arima模型的绘图图和预测数据。我还有一个单选按钮,用于在季节或非季节框中显示项目。我希望仅在单击提交按钮时显示相应的框。例如:如果我在单选按钮中选中了季节性选项并单击预测,那么我想查看季节性图表和季节性预测数据。当前,仪表板仅基于单选按钮中的所选选项显示框。

skin <- Sys.getenv("DASHBOARD_SKIN")
skin <- tolower(skin)
if (skin == "")
  skin <- "black"


sidebar <- dashboardSidebar(
  sidebarSearchForm(label = "Search...", "searchText", "searchButton"),
  sidebarMenu(
    menuItem("Dashboard", tabName = "dashboard", icon = icon("dashboard"))
    )
  )
)

body <- dashboardBody(
  tabItems(
    tabItem("dashboard",

            # Boxes with solid headers
            fluidRow(
              box(
                title = "Enter Stock Code", width = 4, solidHeader = TRUE, status = "primary",
                textInput("StockCode", "StockCode", value = "AAPL"),
                radioButtons("seasonal", "Select", c(NonSeasonal = "NonSeasonal", Seasonal = "Seasonal")),
                actionButton(inputId = "click", label = "Predict")
              )
            ),
            fluidRow(

              box(
                title = "Auto Arima - Non Seasonal",
                status = "primary",
                uiOutput("arima_nonseasonal", height = 350),
                height = 470
              ),
              box(
                title = "Auto Arima - Non Seasonal",
                width = "6",
                tableOutput("arima_nonseasonal_Data"),
                height = 470
              )

            ),

            fluidRow(
              box(
                title = "Auto Arima Seasonal",
                status = "primary",
                uiOutput("arima.seasonal", height = 350),
                height = 470
              ),
              box(
                title = "Auto Arima Seasonal",
                width = "6",
                tableOutput("arima.seasonalData"),
                height = 470
              )

            )

    )
  )
)

header <- dashboardHeader(
  title = "Executive Dashboard"
)

ui <- dashboardPage(header, sidebar, body, skin = skin)

server <- function(input, output, session) {

  output$nonseasonalplot <- renderPlotly({
    qxts = structure(list(y=c(-0.4120000005, -0.452666665083333, -0.458666667316667, -0.460666666416667, -0.505333344133333, -0.506666670233333, -0.50999999045, -0.498666668933333, -0.502666672066667, -0.505333344133333, -0.50200000405, -0.506666680166667, -0.508000006266667, -0.5040000081, -0.501333341, -0.50200000405, -0.502000009016667, -0.504000003133333, -0.50466667115, -0.505333344133333, -0.501333341, -0.503333340083333, -0.496666664883333, -0.5040000081, -0.49799999595, -0.389333337533333, -0.3640000075, -0.365333338566667, -0.3586666733, -0.3599999994, -0.355333338183333, -0.365333338566667, -0.360666667416667, -0.3640000075, -0.3546666652, -0.369999999783333, -0.3653333336, -0.36733333765, -0.396666670833333, -0.469333335766667, -0.4586666673, -0.4639999916, -0.457333331283333, -0.4646666596, -0.4680000047, -0.4687999964, -0.467333336683333, -0.460666661433333, -0.4653333326, -0.4720000029, -0.453333328166667, -0.466000000616667, -0.4646666646, -0.45933333535, -0.464666659633333, -0.4579999993, -0.464666669566667, -0.473999996983333, -0.417333334666667, -0.46400000155, -0.4599999934, -0.46866666775, -0.47200000288, -0.465333337583333, -0.4719999979, -0.462666660516667, -0.46240000126, -0.465333322666667, -0.4673333317, -0.459999993416667, -0.464666659616667, -0.461333329466667, -0.46599999565, -0.461999997483333, -0.461999992516667, -0.466666663683333, -0.457333336283333, -0.46600000065, -0.463999996566667, -0.46400000155, -0.488666658566667, -0.543333326766667, -0.489333341533333, -0.3600000143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.3573333323, -0.464666662133333, -0.3360000037, -0.445333333066667, -0.49333334465, -0.444666661316667, -0.325333339483333, -0.60199998815, -0.33039999454, -0.394666674216667, -0.406666671233333, -0.4066666588, -0.52533333005, -0.552000006066667, -0.6973333458, -0.526000003, -0.565333336583333, -0.451428575185714, -0.3973333314, -0.591999994871429, -0.49120000004, -0.4313333432, -0.197333325966667, -0.545999998833333, -0.49600000976, -0.4595000035875, -0.45920000072, -0.453714281285714, -0.455333337166667, -0.461333334433333, -0.461999992533333, -0.457333331283333, -0.4606666664, -0.456000005183333, -0.4593333254, -0.4579999993, -0.45679999586, -0.455428570485714, -0.454666664183333, -0.453999991183333, -0.452666665083333, -0.464000001533333, -0.456666668216667, -0.45439999696, -0.45666666825, -0.454666664166667, -0.459999998383333, -0.45840000508, -0.459333330366667, -0.394666661816667, -0.367333332983333, -0.2823999971, -0.3446666648, -0.464666659633333, -0.443333327766667, -0.33920000494, -0.332666660333333, -0.363333340716667, -0.43599999546, -0.518000001716667, -0.15933333585, -0.2493333357, -0.43359999356, -0.462666669166667, -0.410000008833333, -0.357333337883333, -0.3615999937, -0.494666665783333, -0.52200000485, -0.29400000225, -0.4527999997, -0.474000004416667, -0.342666663233333, -0.53680000306, -0.423333331933333, -0.498666671416667, -0.439333344516667, -0.46480000914, -0.368666668733333, -0.2673333399, -0.303333333366667, -0.21279999912, -0.398000004383333, -0.444666676216667, -0.63679999114, -0.337333336466667, -0.2599999905 ),
                          date = c(1493139120, 1493139180, 1493139240, 1493139300, 1493139360, 1493139420, 1493139480, 1493139540, 1493139600, 1493139660, 1493139720, 1493139780, 1493139840, 1493139900, 1493139960, 1493140020, 1493140080, 1493140140, 1493140200, 1493140260, 1493140320, 1493140380, 1493140440, 1493140500, 1493140560, 1493140620, 1493140680, 1493140740, 1493140800, 1493140860, 1493140920, 1493140980, 1493141040, 1493141100, 1493141160, 1493141220, 1493141280, 1493141340, 1493141400, 1493141460, 1493141520, 1493141580, 1493141640, 1493141700, 1493141760, 1493141820, 1493141880, 1493141940, 1493142000, 1493142060, 1493142120, 1493142180, 1493142240, 1493142300, 1493142360, 1493142420, 1493142480, 1493142540, 1493142600, 1493142660, 1493142720, 1493142780, 1493142840, 1493142900, 1493142960, 1493143020, 1493143080, 1493143140, 1493143200, 1493143260, 1493143320, 1493143380, 1493143440, 1493143500, 1493143560, 1493143620, 1493143680, 1493143740, 1493143800, 1493143860, 1493143920, 1493143980, 1493144040, 1493144100, 1493144160, 1493144220, 1493144280, 1493144340, 1493144400, 1493144460, 1493144520, 1493144580, 1493144640, 1493144700, 1493144760, 1493144820, 1493144880, 1493144940, 1493145000, 1493145060, 1493145120, 1493145180, 1493145240, 1493145300, 1493145360, 1493145420, 1493145480, 1493145540, 1493145600, 1493145660, 1493145720, 1493145780, 1493145840, 1493145900, 1493145960, 1493146020, 1493146080, 1493146140, 1493146200, 1493146260, 1493146320, 1493146380, 1493146440, 1493146500, 1493146560, 1493146620, 1493146680, 1493146740, 1493146800, 1493146860, 1493146920, 1493146980, 1493147040, 1493147100, 1493147160, 1493147220, 1493147280, 1493147340, 1493147400, 1493147460, 1493147520, 1493147580, 1493147640, 1493147700, 1493147760, 1493147820, 1493147880, 1493147940, 1493148000, 1493148060, 1493148120, 1493148180, 1493148240, 1493148300, 1493148360, 1493148420, 1493148480, 1493148540, 1493148600, 1493148660, 1493148720, 1493148780, 1493148840, 1493148900, 1493148960, 1493149020, 1493149080, 1493149140, 1493149200, 1493149260, 1493149320, 1493149380, 1493149440, 1493149500, 1493149560, 1493149620, 1493149680, 1493149740, 1493149800, 1493149860, 1493149920, 1493149980, 1493150040, 1493150100, 1493150160, 1493150220, 1493150280, 1493150340, 1493150400, 1493150460, 1493150520))
    )

    fit.xts <- auto.arima(qxts$y, seasonal = FALSE)
    forecast_length <- 10
    fore.xts <- forecast(fit.xts, h=forecast_length)

    fore.dates <- seq(as.POSIXct(qxts$date[length(qxts$date)], origin="1970-01-01"), 
                      by=qxts$date[length(qxts$date)] - qxts$date[length(qxts$date)-1], len=forecast_length)

    nonseasonal_p <- plot_ly() %>%
      add_lines(x = as.POSIXct(qxts$date, origin="1970-01-01"), y = qxts$y,
                color = I("black"),
                name = "observed",
                marker=list(mode="lines")) %>%
      add_lines(x = fore.dates, y = fore.xts$mean, color = I("blue"), name = "prediction") %>%
      add_ribbons(x = fore.dates,
                  ymin = fore.xts$lower[, 2],
                  ymax = fore.xts$upper[, 2],
                  color = I("gray95"),
                  name = "95% confidence") %>%
      add_ribbons(x = fore.dates,
                  ymin = fore.xts$lower[, 1],
                  ymax = fore.xts$upper[, 1],
                  color = I("gray80"), name = "80% confidence")

    return(nonseasonal_p)

  })

  #Nonseasonal plot Auto.Arima - plot here  Tile#4 
  output$arima_nonseasonal <- renderUI({
      if (input$seasonal == "NonSeasonal"){
        plotlyOutput("nonseasonalplot")
      }

  })

  nonseasonaltable <- reactive({
    qxts = structure(list(y=c(-0.4120000005, -0.452666665083333, -0.458666667316667, -0.460666666416667, -0.505333344133333, -0.506666670233333, -0.50999999045, -0.498666668933333, -0.502666672066667, -0.505333344133333, -0.50200000405, -0.506666680166667, -0.508000006266667, -0.5040000081, -0.501333341, -0.50200000405, -0.502000009016667, -0.504000003133333, -0.50466667115, -0.505333344133333, -0.501333341, -0.503333340083333, -0.496666664883333, -0.5040000081, -0.49799999595, -0.389333337533333, -0.3640000075, -0.365333338566667, -0.3586666733, -0.3599999994, -0.355333338183333, -0.365333338566667, -0.360666667416667, -0.3640000075, -0.3546666652, -0.369999999783333, -0.3653333336, -0.36733333765, -0.396666670833333, -0.469333335766667, -0.4586666673, -0.4639999916, -0.457333331283333, -0.4646666596, -0.4680000047, -0.4687999964, -0.467333336683333, -0.460666661433333, -0.4653333326, -0.4720000029, -0.453333328166667, -0.466000000616667, -0.4646666646, -0.45933333535, -0.464666659633333, -0.4579999993, -0.464666669566667, -0.473999996983333, -0.417333334666667, -0.46400000155, -0.4599999934, -0.46866666775, -0.47200000288, -0.465333337583333, -0.4719999979, -0.462666660516667, -0.46240000126, -0.465333322666667, -0.4673333317, -0.459999993416667, -0.464666659616667, -0.461333329466667, -0.46599999565, -0.461999997483333, -0.461999992516667, -0.466666663683333, -0.457333336283333, -0.46600000065, -0.463999996566667, -0.46400000155, -0.488666658566667, -0.543333326766667, -0.489333341533333, -0.3600000143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.3573333323, -0.464666662133333, -0.3360000037, -0.445333333066667, -0.49333334465, -0.444666661316667, -0.325333339483333, -0.60199998815, -0.33039999454, -0.394666674216667, -0.406666671233333, -0.4066666588, -0.52533333005, -0.552000006066667, -0.6973333458, -0.526000003, -0.565333336583333, -0.451428575185714, -0.3973333314, -0.591999994871429, -0.49120000004, -0.4313333432, -0.197333325966667, -0.545999998833333, -0.49600000976, -0.4595000035875, -0.45920000072, -0.453714281285714, -0.455333337166667, -0.461333334433333, -0.461999992533333, -0.457333331283333, -0.4606666664, -0.456000005183333, -0.4593333254, -0.4579999993, -0.45679999586, -0.455428570485714, -0.454666664183333, -0.453999991183333, -0.452666665083333, -0.464000001533333, -0.456666668216667, -0.45439999696, -0.45666666825, -0.454666664166667, -0.459999998383333, -0.45840000508, -0.459333330366667, -0.394666661816667, -0.367333332983333, -0.2823999971, -0.3446666648, -0.464666659633333, -0.443333327766667, -0.33920000494, -0.332666660333333, -0.363333340716667, -0.43599999546, -0.518000001716667, -0.15933333585, -0.2493333357, -0.43359999356, -0.462666669166667, -0.410000008833333, -0.357333337883333, -0.3615999937, -0.494666665783333, -0.52200000485, -0.29400000225, -0.4527999997, -0.474000004416667, -0.342666663233333, -0.53680000306, -0.423333331933333, -0.498666671416667, -0.439333344516667, -0.46480000914, -0.368666668733333, -0.2673333399, -0.303333333366667, -0.21279999912, -0.398000004383333, -0.444666676216667, -0.63679999114, -0.337333336466667, -0.2599999905 ),
                          date = c(1493139120, 1493139180, 1493139240, 1493139300, 1493139360, 1493139420, 1493139480, 1493139540, 1493139600, 1493139660, 1493139720, 1493139780, 1493139840, 1493139900, 1493139960, 1493140020, 1493140080, 1493140140, 1493140200, 1493140260, 1493140320, 1493140380, 1493140440, 1493140500, 1493140560, 1493140620, 1493140680, 1493140740, 1493140800, 1493140860, 1493140920, 1493140980, 1493141040, 1493141100, 1493141160, 1493141220, 1493141280, 1493141340, 1493141400, 1493141460, 1493141520, 1493141580, 1493141640, 1493141700, 1493141760, 1493141820, 1493141880, 1493141940, 1493142000, 1493142060, 1493142120, 1493142180, 1493142240, 1493142300, 1493142360, 1493142420, 1493142480, 1493142540, 1493142600, 1493142660, 1493142720, 1493142780, 1493142840, 1493142900, 1493142960, 1493143020, 1493143080, 1493143140, 1493143200, 1493143260, 1493143320, 1493143380, 1493143440, 1493143500, 1493143560, 1493143620, 1493143680, 1493143740, 1493143800, 1493143860, 1493143920, 1493143980, 1493144040, 1493144100, 1493144160, 1493144220, 1493144280, 1493144340, 1493144400, 1493144460, 1493144520, 1493144580, 1493144640, 1493144700, 1493144760, 1493144820, 1493144880, 1493144940, 1493145000, 1493145060, 1493145120, 1493145180, 1493145240, 1493145300, 1493145360, 1493145420, 1493145480, 1493145540, 1493145600, 1493145660, 1493145720, 1493145780, 1493145840, 1493145900, 1493145960, 1493146020, 1493146080, 1493146140, 1493146200, 1493146260, 1493146320, 1493146380, 1493146440, 1493146500, 1493146560, 1493146620, 1493146680, 1493146740, 1493146800, 1493146860, 1493146920, 1493146980, 1493147040, 1493147100, 1493147160, 1493147220, 1493147280, 1493147340, 1493147400, 1493147460, 1493147520, 1493147580, 1493147640, 1493147700, 1493147760, 1493147820, 1493147880, 1493147940, 1493148000, 1493148060, 1493148120, 1493148180, 1493148240, 1493148300, 1493148360, 1493148420, 1493148480, 1493148540, 1493148600, 1493148660, 1493148720, 1493148780, 1493148840, 1493148900, 1493148960, 1493149020, 1493149080, 1493149140, 1493149200, 1493149260, 1493149320, 1493149380, 1493149440, 1493149500, 1493149560, 1493149620, 1493149680, 1493149740, 1493149800, 1493149860, 1493149920, 1493149980, 1493150040, 1493150100, 1493150160, 1493150220, 1493150280, 1493150340, 1493150400, 1493150460, 1493150520))
    )

    fit.xts <- auto.arima(qxts$y, seasonal = FALSE)
    forecast_length <- 10
    fore.xts <- forecast(fit.xts, h=forecast_length)

    return(fore.xts)

    return(nonseasonal_nwforcast)
  })

  #Non seasonal dataAuto.Arima1 - plot here  Tile#5
  output$arima_nonseasonal_Data <- renderTable({
      if (input$seasonal == "NonSeasonal"){
        nonseasonaltable()
      }
  })

  output$seasonalplot<- renderPlotly({

    qxts = structure(list(y=c(-0.4120000005, -0.452666665083333, -0.458666667316667, -0.460666666416667, -0.505333344133333, -0.506666670233333, -0.50999999045, -0.498666668933333, -0.502666672066667, -0.505333344133333, -0.50200000405, -0.506666680166667, -0.508000006266667, -0.5040000081, -0.501333341, -0.50200000405, -0.502000009016667, -0.504000003133333, -0.50466667115, -0.505333344133333, -0.501333341, -0.503333340083333, -0.496666664883333, -0.5040000081, -0.49799999595, -0.389333337533333, -0.3640000075, -0.365333338566667, -0.3586666733, -0.3599999994, -0.355333338183333, -0.365333338566667, -0.360666667416667, -0.3640000075, -0.3546666652, -0.369999999783333, -0.3653333336, -0.36733333765, -0.396666670833333, -0.469333335766667, -0.4586666673, -0.4639999916, -0.457333331283333, -0.4646666596, -0.4680000047, -0.4687999964, -0.467333336683333, -0.460666661433333, -0.4653333326, -0.4720000029, -0.453333328166667, -0.466000000616667, -0.4646666646, -0.45933333535, -0.464666659633333, -0.4579999993, -0.464666669566667, -0.473999996983333, -0.417333334666667, -0.46400000155, -0.4599999934, -0.46866666775, -0.47200000288, -0.465333337583333, -0.4719999979, -0.462666660516667, -0.46240000126, -0.465333322666667, -0.4673333317, -0.459999993416667, -0.464666659616667, -0.461333329466667, -0.46599999565, -0.461999997483333, -0.461999992516667, -0.466666663683333, -0.457333336283333, -0.46600000065, -0.463999996566667, -0.46400000155, -0.488666658566667, -0.543333326766667, -0.489333341533333, -0.3600000143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.3573333323, -0.464666662133333, -0.3360000037, -0.445333333066667, -0.49333334465, -0.444666661316667, -0.325333339483333, -0.60199998815, -0.33039999454, -0.394666674216667, -0.406666671233333, -0.4066666588, -0.52533333005, -0.552000006066667, -0.6973333458, -0.526000003, -0.565333336583333, -0.451428575185714, -0.3973333314, -0.591999994871429, -0.49120000004, -0.4313333432, -0.197333325966667, -0.545999998833333, -0.49600000976, -0.4595000035875, -0.45920000072, -0.453714281285714, -0.455333337166667, -0.461333334433333, -0.461999992533333, -0.457333331283333, -0.4606666664, -0.456000005183333, -0.4593333254, -0.4579999993, -0.45679999586, -0.455428570485714, -0.454666664183333, -0.453999991183333, -0.452666665083333, -0.464000001533333, -0.456666668216667, -0.45439999696, -0.45666666825, -0.454666664166667, -0.459999998383333, -0.45840000508, -0.459333330366667, -0.394666661816667, -0.367333332983333, -0.2823999971, -0.3446666648, -0.464666659633333, -0.443333327766667, -0.33920000494, -0.332666660333333, -0.363333340716667, -0.43599999546, -0.518000001716667, -0.15933333585, -0.2493333357, -0.43359999356, -0.462666669166667, -0.410000008833333, -0.357333337883333, -0.3615999937, -0.494666665783333, -0.52200000485, -0.29400000225, -0.4527999997, -0.474000004416667, -0.342666663233333, -0.53680000306, -0.423333331933333, -0.498666671416667, -0.439333344516667, -0.46480000914, -0.368666668733333, -0.2673333399, -0.303333333366667, -0.21279999912, -0.398000004383333, -0.444666676216667, -0.63679999114, -0.337333336466667, -0.2599999905 ),
                          date = c(1493139120, 1493139180, 1493139240, 1493139300, 1493139360, 1493139420, 1493139480, 1493139540, 1493139600, 1493139660, 1493139720, 1493139780, 1493139840, 1493139900, 1493139960, 1493140020, 1493140080, 1493140140, 1493140200, 1493140260, 1493140320, 1493140380, 1493140440, 1493140500, 1493140560, 1493140620, 1493140680, 1493140740, 1493140800, 1493140860, 1493140920, 1493140980, 1493141040, 1493141100, 1493141160, 1493141220, 1493141280, 1493141340, 1493141400, 1493141460, 1493141520, 1493141580, 1493141640, 1493141700, 1493141760, 1493141820, 1493141880, 1493141940, 1493142000, 1493142060, 1493142120, 1493142180, 1493142240, 1493142300, 1493142360, 1493142420, 1493142480, 1493142540, 1493142600, 1493142660, 1493142720, 1493142780, 1493142840, 1493142900, 1493142960, 1493143020, 1493143080, 1493143140, 1493143200, 1493143260, 1493143320, 1493143380, 1493143440, 1493143500, 1493143560, 1493143620, 1493143680, 1493143740, 1493143800, 1493143860, 1493143920, 1493143980, 1493144040, 1493144100, 1493144160, 1493144220, 1493144280, 1493144340, 1493144400, 1493144460, 1493144520, 1493144580, 1493144640, 1493144700, 1493144760, 1493144820, 1493144880, 1493144940, 1493145000, 1493145060, 1493145120, 1493145180, 1493145240, 1493145300, 1493145360, 1493145420, 1493145480, 1493145540, 1493145600, 1493145660, 1493145720, 1493145780, 1493145840, 1493145900, 1493145960, 1493146020, 1493146080, 1493146140, 1493146200, 1493146260, 1493146320, 1493146380, 1493146440, 1493146500, 1493146560, 1493146620, 1493146680, 1493146740, 1493146800, 1493146860, 1493146920, 1493146980, 1493147040, 1493147100, 1493147160, 1493147220, 1493147280, 1493147340, 1493147400, 1493147460, 1493147520, 1493147580, 1493147640, 1493147700, 1493147760, 1493147820, 1493147880, 1493147940, 1493148000, 1493148060, 1493148120, 1493148180, 1493148240, 1493148300, 1493148360, 1493148420, 1493148480, 1493148540, 1493148600, 1493148660, 1493148720, 1493148780, 1493148840, 1493148900, 1493148960, 1493149020, 1493149080, 1493149140, 1493149200, 1493149260, 1493149320, 1493149380, 1493149440, 1493149500, 1493149560, 1493149620, 1493149680, 1493149740, 1493149800, 1493149860, 1493149920, 1493149980, 1493150040, 1493150100, 1493150160, 1493150220, 1493150280, 1493150340, 1493150400, 1493150460, 1493150520))
    )

    fit.xts <- auto.arima(qxts$y, seasonal = TRUE)
    forecast_length <- 10
    fore.xts <- forecast(fit.xts, h=forecast_length)

    fore.dates <- seq(as.POSIXct(qxts$date[length(qxts$date)], origin="1970-01-01"), 
                      by=qxts$date[length(qxts$date)] - qxts$date[length(qxts$date)-1], len=forecast_length)

    seasonal_p <- plot_ly() %>%
      add_lines(x = as.POSIXct(qxts$date, origin="1970-01-01"), y = qxts$y,
                color = I("black"),
                name = "observed",
                marker=list(mode="lines")) %>%
      add_lines(x = fore.dates, y = fore.xts$mean, color = I("blue"), name = "prediction") %>%
      add_ribbons(x = fore.dates,
                  ymin = fore.xts$lower[, 2],
                  ymax = fore.xts$upper[, 2],
                  color = I("gray95"),
                  name = "95% confidence") %>%
                  add_ribbons(x = fore.dates,
                              ymin = fore.xts$lower[, 1],
                              ymax = fore.xts$upper[, 1],
                              color = I("gray80"), name = "80% confidence")

    return(seasonal_p)
  })

  output$seasonalNotAuth <- renderPrint({
    return("You are NOT authenticated")
  })

  #Auto.Arima Seasonal 
  output$arima.seasonal <- renderUI({
      if (input$seasonal == "Seasonal"){
        plotlyOutput("seasonalplot")
      }
  })

  seasonaldata <- reactive({

    qxts = structure(list(y=c(-0.4120000005, -0.452666665083333, -0.458666667316667, -0.460666666416667, -0.505333344133333, -0.506666670233333, -0.50999999045, -0.498666668933333, -0.502666672066667, -0.505333344133333, -0.50200000405, -0.506666680166667, -0.508000006266667, -0.5040000081, -0.501333341, -0.50200000405, -0.502000009016667, -0.504000003133333, -0.50466667115, -0.505333344133333, -0.501333341, -0.503333340083333, -0.496666664883333, -0.5040000081, -0.49799999595, -0.389333337533333, -0.3640000075, -0.365333338566667, -0.3586666733, -0.3599999994, -0.355333338183333, -0.365333338566667, -0.360666667416667, -0.3640000075, -0.3546666652, -0.369999999783333, -0.3653333336, -0.36733333765, -0.396666670833333, -0.469333335766667, -0.4586666673, -0.4639999916, -0.457333331283333, -0.4646666596, -0.4680000047, -0.4687999964, -0.467333336683333, -0.460666661433333, -0.4653333326, -0.4720000029, -0.453333328166667, -0.466000000616667, -0.4646666646, -0.45933333535, -0.464666659633333, -0.4579999993, -0.464666669566667, -0.473999996983333, -0.417333334666667, -0.46400000155, -0.4599999934, -0.46866666775, -0.47200000288, -0.465333337583333, -0.4719999979, -0.462666660516667, -0.46240000126, -0.465333322666667, -0.4673333317, -0.459999993416667, -0.464666659616667, -0.461333329466667, -0.46599999565, -0.461999997483333, -0.461999992516667, -0.466666663683333, -0.457333336283333, -0.46600000065, -0.463999996566667, -0.46400000155, -0.488666658566667, -0.543333326766667, -0.489333341533333, -0.3600000143, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -0.3573333323, -0.464666662133333, -0.3360000037, -0.445333333066667, -0.49333334465, -0.444666661316667, -0.325333339483333, -0.60199998815, -0.33039999454, -0.394666674216667, -0.406666671233333, -0.4066666588, -0.52533333005, -0.552000006066667, -0.6973333458, -0.526000003, -0.565333336583333, -0.451428575185714, -0.3973333314, -0.591999994871429, -0.49120000004, -0.4313333432, -0.197333325966667, -0.545999998833333, -0.49600000976, -0.4595000035875, -0.45920000072, -0.453714281285714, -0.455333337166667, -0.461333334433333, -0.461999992533333, -0.457333331283333, -0.4606666664, -0.456000005183333, -0.4593333254, -0.4579999993, -0.45679999586, -0.455428570485714, -0.454666664183333, -0.453999991183333, -0.452666665083333, -0.464000001533333, -0.456666668216667, -0.45439999696, -0.45666666825, -0.454666664166667, -0.459999998383333, -0.45840000508, -0.459333330366667, -0.394666661816667, -0.367333332983333, -0.2823999971, -0.3446666648, -0.464666659633333, -0.443333327766667, -0.33920000494, -0.332666660333333, -0.363333340716667, -0.43599999546, -0.518000001716667, -0.15933333585, -0.2493333357, -0.43359999356, -0.462666669166667, -0.410000008833333, -0.357333337883333, -0.3615999937, -0.494666665783333, -0.52200000485, -0.29400000225, -0.4527999997, -0.474000004416667, -0.342666663233333, -0.53680000306, -0.423333331933333, -0.498666671416667, -0.439333344516667, -0.46480000914, -0.368666668733333, -0.2673333399, -0.303333333366667, -0.21279999912, -0.398000004383333, -0.444666676216667, -0.63679999114, -0.337333336466667, -0.2599999905 ),
                          date = c(1493139120, 1493139180, 1493139240, 1493139300, 1493139360, 1493139420, 1493139480, 1493139540, 1493139600, 1493139660, 1493139720, 1493139780, 1493139840, 1493139900, 1493139960, 1493140020, 1493140080, 1493140140, 1493140200, 1493140260, 1493140320, 1493140380, 1493140440, 1493140500, 1493140560, 1493140620, 1493140680, 1493140740, 1493140800, 1493140860, 1493140920, 1493140980, 1493141040, 1493141100, 1493141160, 1493141220, 1493141280, 1493141340, 1493141400, 1493141460, 1493141520, 1493141580, 1493141640, 1493141700, 1493141760, 1493141820, 1493141880, 1493141940, 1493142000, 1493142060, 1493142120, 1493142180, 1493142240, 1493142300, 1493142360, 1493142420, 1493142480, 1493142540, 1493142600, 1493142660, 1493142720, 1493142780, 1493142840, 1493142900, 1493142960, 1493143020, 1493143080, 1493143140, 1493143200, 1493143260, 1493143320, 1493143380, 1493143440, 1493143500, 1493143560, 1493143620, 1493143680, 1493143740, 1493143800, 1493143860, 1493143920, 1493143980, 1493144040, 1493144100, 1493144160, 1493144220, 1493144280, 1493144340, 1493144400, 1493144460, 1493144520, 1493144580, 1493144640, 1493144700, 1493144760, 1493144820, 1493144880, 1493144940, 1493145000, 1493145060, 1493145120, 1493145180, 1493145240, 1493145300, 1493145360, 1493145420, 1493145480, 1493145540, 1493145600, 1493145660, 1493145720, 1493145780, 1493145840, 1493145900, 1493145960, 1493146020, 1493146080, 1493146140, 1493146200, 1493146260, 1493146320, 1493146380, 1493146440, 1493146500, 1493146560, 1493146620, 1493146680, 1493146740, 1493146800, 1493146860, 1493146920, 1493146980, 1493147040, 1493147100, 1493147160, 1493147220, 1493147280, 1493147340, 1493147400, 1493147460, 1493147520, 1493147580, 1493147640, 1493147700, 1493147760, 1493147820, 1493147880, 1493147940, 1493148000, 1493148060, 1493148120, 1493148180, 1493148240, 1493148300, 1493148360, 1493148420, 1493148480, 1493148540, 1493148600, 1493148660, 1493148720, 1493148780, 1493148840, 1493148900, 1493148960, 1493149020, 1493149080, 1493149140, 1493149200, 1493149260, 1493149320, 1493149380, 1493149440, 1493149500, 1493149560, 1493149620, 1493149680, 1493149740, 1493149800, 1493149860, 1493149920, 1493149980, 1493150040, 1493150100, 1493150160, 1493150220, 1493150280, 1493150340, 1493150400, 1493150460, 1493150520))
    )

    fit.xts <- auto.arima(qxts$y, seasonal = TRUE)
    forecast_length <- 10
    fore.xts <- forecast(fit.xts, h=forecast_length)

    return(fore.xts)
  })

  #Auto.Arima Seasonal data
  output$arima.seasonalData <- renderTable({
      if (input$seasonal == "Seasonal"){
        seasonaldata()
      }
  })

}

shinyApp(ui, server)

我希望仪表板等我按下“预测”按钮,然后根据所选的单选按钮选项在框中显示图表和预测数据。

r shiny radiobuttonlist action-button
1个回答
0
投票

input$seasonal是反应性的;当它更改值时,它会触发任何使用它的反应堆或观察者(也包括renderXXX)的更新。您的操作按钮input$click是反应性的,并且遵循完全相同的规则。它的值是一个简单的整数,用于计算在该会话中单击按钮的次数。如果要使用单选按钮的值,请使用isolate(input$seasonal),但是

not

进行更改会触发更新。然后要通过单击操作按钮来触发反应式,观察者或renderXXX,只需在某处包含input$click,即:

output$plot <- renderPlot({ if (isolate(input$seasonal) == 'foo') { data = "foo" } else { data = "bar" } input$click # <--- this is where we react to the action button plot(data) })

© www.soinside.com 2019 - 2024. All rights reserved.