繁体   English   中英

R闪亮的应用程序错误shinyBS

[英]R shiny app error shinyBS

我有一个如下的ui

library(shiny)

shinyUI(pageWithSidebar(
  headerPanel(tags$b(tags$em("Stock price testing for GBM"))),

  sidebarPanel(
    wellPanel(

      list(tags$head(tags$style("body {background-color: #E0F2F7; }"))),

      helpText(
      tags$div(
        tags$p("Welcome to this GBM test app that checks if geometrical brownian motion is a good model to predict stock prices. 
Input any stock ticker, whether it being an individual stock or an entire index, and click analysis to check if the assumptions of geometrical 
brownian motion holds for your ticker and range of dates."), 
        tags$p("Click",tags$a(href="https://uk.finance.yahoo.com/lookup", "here"),"to look for a symbol."))), 


      textInput("symb", "Symbol", "^FTSE"),
      bsAlert(inputId = "alert_anchor"),

      dateRangeInput("dates", 
                     "Date range",
                     start = "2015-01-01", 
                     end = as.character(Sys.Date())),
      textOutput("DateRange"),
      fluidRow(column(12,align="right",
      div(style="display:inline-block",submitButton("Analysis")))),
      fluidRow(column(12,tags$div(
        tags$p(" "),tags$p(" ")))),
      fluidRow(column(6,align="right",
      div(style="display:inline-block",downloadButton('downloadData','Download Data'))), column(6,align="right",
      div(style="display:inline-block",actionButton("action", label = "Help"))),width=6
      ))),





    ))))

和服务器一样

# server.R

"quantmod" %in% rownames(installed.packages())
if("quantmod" %in% rownames(installed.packages()) == FALSE) {install.packages("quantmod")}
"randtests" %in% rownames(installed.packages())
if("randtests" %in% rownames(installed.packages()) == FALSE) {install.packages("randtests")}
"fractal" %in% rownames(installed.packages())
if("fractal" %in% rownames(installed.packages()) == FALSE) {install.packages("fractal")}
"tseries" %in% rownames(installed.packages())
if("tseries" %in% rownames(installed.packages()) == FALSE) {install.packages("tseries")}
"car" %in% rownames(installed.packages())
if("car" %in% rownames(installed.packages()) == FALSE) {install.packages("car")}
"shinyBS" %in% rownames(installed.packages())
if("shinyBS" %in% rownames(installed.packages()) == FALSE) {install.packages("shinyBS")}
"rmarkdown" %in% rownames(installed.packages())
if("rmarkdown" %in% rownames(installed.packages()) == FALSE) {install.packages("rmarkdown")}

library("quantmod")
library("randtests") 
library("fractal")
library("tseries")
library("car")
library("shinyBS")


shinyServer(function(input, output,session) {
  getSymbols.warning4.0=FALSE
  options("getSymbols.warning4.0"=FALSE)

  dataInput <- reactive({
    data<-tryCatch({
      #if there is a bsAlert, close it
      closeAlert(session, "alert")
      #try to get the symbols
      getSymbols(input$symb, src = "yahoo", 
                 from = input$dates[1],
                 to = input$dates[2],
                 auto.assign = FALSE)},
      #if there is an error
      error=function(cond) {
        #create the bsAlert
        createAlert(session, inputId = "alert_anchor",
                    alertId="alert",
                    message = "Please enter a valid symbol and data range",
                    type = "info",
                    append="false", 
                    dismiss = FALSE
        )
        #return an empty string
        return("")
      })
    data
  })
  lg.ret<-reactive({
    validate(need(dataInput()!="","") )
    dailyReturn(dataInput(),type="log")

  })

  output$DateRange <- renderText({
    validate(
      need(input$dates[2] > input$dates[1], "End date is earlier than the start date")
    )
    lg.day.ret.vec<-lg.ret.vec()

      validate(
        need(length(lg.day.ret.vec) > 5, "Must choose a greater range of dates for accurate test results"))

    paste("Your date range is", 
          difftime(input$dates[2], input$dates[1], units="days"),
          "days")
  })

  lg.ret.vec<-reactive({
    validate(need(dataInput()!="","") )
    as.vector(dailyReturn(dataInput(),type="log"))

  })



})

但是每当我从R运行应用程序时,我总是会收到此错误ERROR: could not find function "bsAlert" 但是要修复此错误,我只需在控制台中运行library("shinyBS") ,以便打开库。 看到我已经在我的服务器中有这条线,为什么我总是必须在我的控制台中手动运行它? 有没有办法让我不再收到此错误,因为库会自动加载用户选择运行应用程序。

谢谢

创建一个global.R文件,在其中定义要在ui.Rserver.R上使用的包

    #global.r
library("quantmod")
library("randtests") 
library("fractal")
library("tseries")
library("car")
library("shinyBS")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM