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.R
和 server.R
上使用的包
#global.r
library("quantmod")
library("randtests")
library("fractal")
library("tseries")
library("car")
library("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.R
和 server.R
#global.r
library("quantmod")
library("randtests")
library("fractal")
library("tseries")
library("car")
library("shinyBS")