首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发亮的应用程序错误shinyBS

发亮的应用程序错误shinyBS
EN

Stack Overflow用户
提问于 2015-03-02 03:23:55
回答 1查看 694关注 0票数 0

我有如下所示的ui

代码语言:javascript
复制
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
      ))),





    ))))

而服务器作为

代码语言:javascript
复制
# 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"),以便打开库。既然我的服务器中已经有了这一行,为什么我总是要在我的控制台中手动运行?有没有一种方法,使我不再得到这个错误,因为库将自动加载用户选择运行应用程序。

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-03-02 05:43:17

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

代码语言:javascript
复制
    #global.r
library("quantmod")
library("randtests") 
library("fractal")
library("tseries")
library("car")
library("shinyBS")
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28802222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档