【问题标题】:Shiny building 2 graphs one below the otherShiny building 2 一个在另一个之下的图表
【发布时间】:2017-09-21 21:32:15
【问题描述】:

我已经下载了一个使用闪亮的示例,我想在其中添加一个简单的技术指标。

我的问题是我无法真正看到第二张图。 有什么帮助建议吗? 我已阅读此内容Plotting the same output in two tabPanels in shiny R Shiny: How to assign the same plot to two different plotOutput 我做的完全一样,或者至少我认为。所以我需要一点帮助,请

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)

【问题讨论】:

    标签: r shiny


    【解决方案1】:

    这应该可以完成工作

    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)
    

    【讨论】:

      【解决方案2】:

      假设第一个是dygraph,第二个是普通的

      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)
      

      -输出

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-02-29
        • 2015-07-23
        • 1970-01-01
        • 2015-06-04
        • 1970-01-01
        • 1970-01-01
        • 2017-01-03
        • 1970-01-01
        相关资源
        最近更新 更多