我已经下载了一个使用闪亮的例子,我想为它添加一个简单的技术指标。
我的问题是我无法真正看到第二张图。 任何帮助建议? 我已阅读: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)
答案 0 :(得分: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)
-output
答案 1 :(得分:2)
这应该做的工作
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)