首页 > 解决方案 > 我创建了一个闪亮的应用程序来显示所选公司的股票价格图。如何以表格形式显示价格?

问题描述

我创建了一个闪亮的应用程序来显示所选公司的股价图。我也想以表格形式显示价格,但我无法做到。在尝试错误消息状态时 cannot coerce class ‘c("reactiveExpr", "reactive")’ to a data.frame。代码如下:

# Load packages ----
library(shiny)
library(quantmod)

#edited code.this可以直接运行

# User interface ----
ui <- fluidPage(
  titlePanel("stockVis"),

  sidebarLayout(
    sidebarPanel(
      helpText("Select a stock to examine.

        Information will be collected from Yahoo finance."),
      textInput("symb", "Symbol", "SPY"),

      dateRangeInput("dates",
                     "Date range",
                     start = "2013-01-01",
                     end = as.character(Sys.Date())),

      br(),
      br(),

      checkboxInput("log", "Plot y axis on log scale",
                    value = FALSE)

      #checkboxInput("adjust",
                    #"Adjust prices for inflation", value = FALSE)
    ),

    mainPanel(plotOutput("plot"), tableOutput("view")))
  )


# Server logic
server <- function(input, output) {

  dataInput <- reactive({
     getSymbols(input$symb, src = "yahoo",
               from = input$dates[1],
               to = input$dates[2],
               auto.assign = FALSE)
  })

  output$plot <- renderPlot({

    chartSeries(dataInput(), theme = chartTheme("white"),
                type = "line", log.scale = input$log, TA = NULL)
  })

  output$view <- renderTable({(dataInput )
  }, include.rownames = TRUE)

}

# Run the app
shinyApp(ui, server)

标签: rshiny

解决方案


As the error says its a reactive function so you have to use it as such: dataInput() and not dataInput

output$view <- renderTable({ dataInput() }, include.rownames = TRUE)


推荐阅读