editing a table in r shiney

ibrary(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)

here is my code for my current r shiny document, it is outputting a data table of the input stock as requested, however how would I go about editing the table 'data' before outputting it , for example adding a column with moving averages inside it

Hi @georgeloftus. There are some suggestions. Change the textInput to dateInput for the input$date and input$dateto which can facilitate date input easier. And I code the addition column of moving average for 3 rows. Hope it can help.

library(quantmod)
library(shiny)
library(tidyverse)

ui <- fluidPage(
 textInput("Stock","Input Stock"),
 dateInput("Date","Input Start Date"),
 dateInput("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({
  volume <- as.numeric(data()[, 5])
  mean_volume <- map_dbl(1:length(volume), ~{mean(volume[.x : min(.x + 3, length(volume))])})

  data() %>%
   as.data.frame() %>%
   mutate(mean_volume = mean_volume)
 })
 
}
shinyApp(ui, server)

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.