最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

stock - when publishing my shiny app, the layout is chopped up where I can only see parts of the dashboard and plot; in desktop

programmeradmin4浏览0评论

Stock tracking shiny app with quantmod: I've attempted many adjustments to the following code but I keep having display problems when I publish on a server. the bottom half of the dashboard is cut off and the bottom half of the stock display is cut off. I have tried adjust the YAML code with Fillpage True and I have tried adjusting the mainPanel div code. If I run the code in browser mode it looks great / no problems. Any help is greatly appreciated


runtime: shiny



rm(list=ls(all=TRUE))

# Load the libraries
library(shiny)
library(quantmod)

# Define UI for the app
ui <- fillPage(padding = 1,
  titlePanel("Stock Chart"),
  fillRow(
    fillCol(flex = c(30, 39),
      sidebarPanel(
        textInput("symbol", "Enter Stock Symbol, All Caps:", value = "AAPL"),
        dateRangeInput("dates", "Select Date Range",
                       start = Sys.Date() - 700),
        actionButton("getData", "Get Data"),
        checkboxInput("showEMA", "Show Exp Moving Average", value = TRUE),
        numericInput("emaPeriod", "EMA Period", value = 50, min = 1)
      ),
      mainPanel(width = "100%",
                div(style = "height: 600px;",
        plotOutput("stockPlot", height = "59%"))
      )
    )
  )
)

# Define server logic
server <- function(input, output) {
  stockData <- reactiveVal(NULL) # Initialize reactiveVal to store stock data

  observeEvent(input$getData, {
    newData <- getSymbols(input$symbol, src = "yahoo",
                              from = input$dates[1],
                              auto.assign = FALSE)
    stockData(newData) # Update reactiveVal with new data
  })

  output$stockPlot <- renderPlot({
    data <- stockData() # Get data from reactiveVal
    if (!is.null(data)) { # Check if data is available
      chartSeries(data, name = input$symbol, TA = c(addBBands(draw = 'bands', sd = 2, n = 60), addRSI()),
                  theme = chartTheme("white"))
      if (input$showEMA) {
        addEMA(n = input$emaPeriod)
      }
    }
  })
}

# Run the application
shinyApp(ui = ui, server = server)


I removed YAML fillpage / did not work I adjusted the mainpanel div with several height/width changes and nothing worked

In browser mode, everything looks great and works as expected when I run the chunk

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论