0

我一直在使用 Shiny 包,有一个功能,用户可以从选项列表中进行选择,根据选择,情节将更新。但是,现在应用程序不会在选择更改时更新。

server.R
----------
library(shiny)
library(quantmod)
library(TTR)

shinyServer(function(input, output, session) {

  selectedsymbol <- reactive({
    symbol <- input$selectstock
  })

  output$stockplotoverview <- renderPlot({
    symbolinput <- selectedsymbol()
    getSymbols(symbolinput)
    chartSeries(get(symbolinput))
    addMACD()
    addBBands()
  })

  output$candlechart <- renderPlot({
    symbolinput <- input$selectstock
    getSymbols(symbolinput)
    candleChart(get(symbolinput),multi.col=TRUE,theme="white")
  })

  output$barchart <- renderPlot({
    symbolinput <- input$selectstock
    getSymbols(symbolinput)
    barChart(get(symbolinput)) 
  })

})

ui.R
library(shiny)

shinyUI(fluidPage(

  # Application title
  titlePanel("Hello Shiny!"),

  # Sidebar component
  sidebarLayout(
    sidebarPanel(
      selectInput("selectstockset", label = h3("Select the stock set"), choices = list("My Stock set" = 1, 
                                                                                        "Good Stock Set" = 2,
                                                                                        "Customize" = 3), selected = 1),
      selectInput("selectalgo", label = h3("Select the algorithm"), choices = list("Worst Increment" = 1, 
                                                                                        "PAMR" = 2,
                                                                                        "SMA" = 3), selected = 1),
      dateRangeInput("daterange", label = h3("Date Range")),
      submitButton("Simulate")

    ),

    # Show a plot of the generated distribution
    mainPanel(
      tabsetPanel(
        tabPanel("Stock Set",
                   helpText("Select a stock to examine. 
                            Information will be collected from yahoo finance."),

                 textInput("stocksetname", label = h4("Stock Set Name"), 
                           value = "Enter text...") ,
#                  uiOutput("selectstock"),
                 selectInput("selectstock", label = h4("Select the stock"), choices = list("AAPL" = "AAPL",
                                                                                            "SBUX" = "SBUX",
                                                                                            "GS" = "GS")),
                 tabsetPanel(
                   tabPanel("Overview",
                            plotOutput("stockplotoverview")
                            ),
                   tabPanel("Candle Chart",
                            plotOutput("candlechart")
                            ),
                   tabPanel("Bar Chart",
                            plotOutput("barchart"))
                 ),

                hr(),
                fluidRow(
                  column(3,
                         actionButton("addtostockset","Add to stock set"),
                         tags$style(type='text/css', "#addtostockset { align: right;}")
                  ),
                  column(3,
                         actionButton("confirm","Confirm stock set"),
                         tags$style(type='text/css', "#confirm { align: right; }")
                  )
                )),
        tabPanel("Simulation Window"),
        tabPanel("Statistical Result")
    )
  )
)))
4

1 回答 1

0

您的反应导体没有返回任何内容:

  selectedsymbol <- reactive({
    symbol <- input$selectstock
  })

利用

  selectedsymbol <- reactive({
    symbol <- input$selectstock
    return(symbol)
  })
于 2014-08-11T09:27:11.983 回答