mercredi 20 septembre 2017

If condition in Shiny server

I'm trying to manipulate a dataframe based on the input. Here's my code:

library(shiny)
library(quantmod)
ui <- fluidPage(
  plotOutput("chart", click = "SD1"),
  radioButtons(
    "term",
    "Term",
    choices = c("Daily", "Weekly", "Monthly"),
  ))

server <- function(input, output){
  df1 <- reactive(getSymbols("JPM", src = "google", auto.assign = F))
  output$chart <- renderPlot(
    if (input$term == "Weekly") {
      df <- to.weekly(df1())
    }
    else if (input$term == "Monthly") {
      df <- to.monthly(df1())
    }
    else {
      df <- df1()
    }
    chartSeries(
      df()
    )
  )
}

shinyApp(ui, server)

So why my if condition doesn't work? Thank you very much!

Aucun commentaire:

Enregistrer un commentaire