1

I have downloaded an example of using shiny and I want to add a simple technical indicator to it.

My problem is that I cannot really see the second graph. Any help suggestion? I have read this: Plotting the same output in two tabPanels in shiny and R Shiny: How to assign the same plot to two different plotOutput I DO exactly the same or at least I think. So I need a small help on that, please

library(shiny)
ui <- shinyUI(fluidPage(
  titlePanel("Simple Stock Charting App"),

      sidebarLayout(
        sidebarPanel(

          textInput("symb", label = h3("Input a Valid Stock Ticker"), value = "GE") 
        ),

           ### uncomment for dygraphs chart
        mainPanel(dygraphOutput("plot")),
        mainPanel(plotOutput("plot2"))
      )
    ))

    library(quantmod)
    library(dygraphs)
    library(TTR)
    server <- shinyServer(function(input, output) {

      dataInput <- reactive({

        prices <- getSymbols(input$symb, auto.assign = FALSE)

      })

      output$plot <- renderDygraph({renderPlot

        prices <- dataInput()

        dygraph(Ad(prices)) %>%
          dyRangeSelector() 
        })

        output$plot2 <- renderPlot({

          prices <- dataInput()
          prices <- Ad(prices)
          plotOutput((RSI(prices, n = 14))) %>%  dyRangeSelector()

           })
    })


    shinyApp(ui,server)
Uwe
  • 41,420
  • 11
  • 90
  • 134
J.Ze
  • 73
  • 2
  • 11

2 Answers2

4

This should do the job

library(shiny)
library(quantmod)
library(dygraphs)
library(TTR)
ui <- shinyUI(fluidPage(
  titlePanel("Simple Stock Charting App"),

  sidebarLayout(
    sidebarPanel(
      textInput("symb", label = h3("Input a Valid Stock Ticker"), value = "GE") 
    ),

    ### uncomment for dygraphs chart
    mainPanel(dygraphOutput("plot"),plotOutput("plot2"))
  )
))


server <- shinyServer(function(input, output) {

  dataInput <- reactive({
    prices <- getSymbols(input$symb, auto.assign = FALSE)
  })

  output$plot <- renderDygraph({renderPlot
    dygraph(Ad(dataInput())) %>%dyRangeSelector() 
  })

  output$plot2 <- renderPlot({
    plot((RSI(Ad(dataInput()), n = 14))) 
  })
})


shinyApp(ui,server)

enter image description here

Pork Chop
  • 28,528
  • 5
  • 63
  • 77
2

Assuming that the first is dygraph and the second one a normal one

library(shiny) 
library(quantmod)
library(dygraphs)
library(TTR)

ui <- shinyUI(fluidPage( titlePanel("Simple Stock Charting App"),

                                        sidebarLayout(
                                          sidebarPanel(

                                            textInput("symb", label = h3("Input a Valid Stock Ticker"), value = "GE") 
                                          ),


                                          mainPanel(fluidRow(dygraphOutput("plot"),
                                                     plotOutput("plot2")))
                                        )
))


server <- shinyServer(function(input, output) {

  dataInput <- reactive({

    prices <- getSymbols(input$symb, auto.assign = FALSE)

  })

  output$plot <- renderDygraph({renderPlot

    prices <- dataInput()

    dygraph(Ad(prices)) %>%
      dyRangeSelector() 
  })

  output$plot2 <- renderPlot({

    prices <- dataInput()
    #prices <- Ad(prices)
    plot(prices)

  })
})


shinyApp(ui,server)

-output

enter image description here

akrun
  • 874,273
  • 37
  • 540
  • 662