r - 如何在 r shiny 中编辑表格
问题描述
library(quantmod)
library(shiny)
ui <- fluidPage(
textInput("Stock","Input Stock"),
textInput("Date","Input Start Date"),
textInput("Dateto","Input End Date"),
actionButton("GO","GO"),
tableOutput("table")
)
server <- function(input, output, session){
data <- eventReactive(input$GO,{
req(input$Stock)
getSymbols(input$Stock,src = "yahoo", from=input$Date,to=input$Dateto,auto.assign=F)
})
output$table <- renderTable({
data()
})
}
shinyApp(ui, server)
这是我当前 r shiny 文档的代码,它正在按要求输出输入股票的数据表,但是我将如何在输出之前编辑表“数据”,例如在其中添加一个带有移动平均线的列
解决方案
如果您不需要将data
对象保留为xts
zoo
,则一种选择是将调用结果存储到getSymbols
,转换为data.frame
,然后分配一个新列。在下面的示例中,我为您的输入任意选择值(跟踪过去 90 天的 AAPL 股票),并使用以下rollmeanr()
函数计算滚动 7 天平均收盘价zoo
:
raw_data <- getSymbols("AAPL",src = "yahoo", from=Sys.Date()-90,to=Sys.Date(),auto.assign=F)
df <- as.data.frame(raw_data)
# k is the window size for rolling mean
# fill = NA tells the function to fill missing values with NA
df$moving_7_day <- rollmeanr(df$AAPL.Close, k = 7, fill = NA)
推荐阅读
- laravel - Laravel 表单请求验证存储和更新使用相同的验证
- node.js - 使用文件夹导入模块并将数据传递给nodejs中的模块
- c - 索引怎么可能是字符串(i[s])?
- amazon-s3 - Oozie 在 EMR 上将操作数据路径从 S3 更改为 hdfs
- axios - Nuxt:在 .ENV 中设置 Axios BaseURL 不起作用?
- python - 预算午餐和晚餐的 Web Scraping Tabelog
- python - 映射 Django url 和视图
- artificial-intelligence - PDDL AI 规划中的一个错误
- entity-framework-core - 包含在实体框架中的问题
- python - Python Kivy:动态分配小部件ID的问题