我正在尝试构建我的第一个闪亮的应用程序,我希望我的应用程序根据用户选择的输入读取不同的文件。我已设法构建ui.R,server.R和helper.R函数,以便我没有收到错误,但我的应用程序无法正常工作,即文件无法加载。当我选择不同的输入时没有任何反应,看来我的Helper.R脚本中的读取文件功能不起作用。我已经被困在这几天了,我非常感谢能帮助你实现这一目标。
shinyUI(fluidPage(
titlePanel(“Search RSQRM Asset Data”),
fluidRow(
column(3,
selectInput(“model”, label = h3(“Select Model”),
choices = c(“RSQRM Global”, “RSQRM Europe”,”RSQRM US”,”RSQRM Japan”,”RSQRM Asia ex-JP”), selected = ‘RSQRM Global’)),
column(3,
selectInput(“modelCurrency”, label = h3(“Select Model Currency”),
choices = c(“USD”,”EUR”,”JPY”), selected = ‘EUR’)),
column(3,
dateInput(“modelDate”,
label = h3(“Select Model Date”),
value = “2014-04-23″)),
column(3,
radioButtons(“modelVersion”, label = h3(“L or G Version”),
choices = c(“Local Currency Exposure”, “Global Currency Exposure”),selected = “Local Currency Exposure”)),
helpText(“Note: Select the correct combination of model region and base currency.”),
submitButton(“Update View”)
),
# Create a new row for the table.
fluidRow(
dataTableOutput(outputId=”assetData”)
)
))
=============
library(timeDate);library(data.table)
source("helper.R")
# Define a server for the Shiny app
shinyServer(function(input, output) {
sModelPath<-'T:/Documents/Rsquared/RSQRM/'
#Assign switch values for the input fields
dfAssetData <- reactive({
sModel <- switch(input$model, "RSQRM Global"==as.character('GlobalDev'),
"RSQRM Europe"=as.character('Europe'),
"RSQRM US"=as.character('US'),
"RSQRM Japan"=as.character('Japan'),
"RSQRM Asia ex-JP"=as.character('AsiaExJP'))
sModelCurrency <- switch(input$modelCurrency, "USD"=as.character('USD'),"EUR"=as.character('EUR'),"JPY"=as.character('JPY'))
sModelVersion <- switch( input$modelVersion, "Local Currency Exposure"="", "Global Currency Exposure"=as.character("_G"))
sModelDate <- input$modelDate
readAssetDataFile(sModelPath=sModelPath,sModel=sModel,sModelCurrency=sModelCurrency,sModelDate=sModelDate,sModelVersion=sModelVersion)
})
output$assetData <- renderDataTable(
dfAssetData,options=list(iDisplayLength = 25)
)
})
=============
# Constructs File Path and reads File
readAssetDataFile <- function(sModelPath,sModel,sModelCurrency,sModelDate,sModelVersion)
{
#Build Model file path
if(sModel=='GlobalDev')
{
sModelFile<-paste(sModelPath,sModel,'/outputData/','FF_RSQ_RSQRM_GlobalDev_v2_19_8_',sModelCurrency,'_',format(sModelDate,"%Y%m%d"),'_AssetData.txt',sep='')
} else if(sModel=='Europe')
{
sModelFile<-paste(sModelPath,sModel,'/outputData/','FF_RSQ_RSQRM_Europe',sModelVersion,'_v2_19_9_',sModelCurrency,'_',format(sModelDate,"%Y%m%d"),'_AssetData.txt',sep='')
} else if(sModel=='US')
{
sModelFile<-paste(sModelPath,sModel,'/outputData/','FF_RSQRM_US_v2_19_7_',sModelCurrency,'_',format(sModelDate,"%Y%m%d"),'_AssetData.txt',sep='')
} else if(sModel=='Japan')
{
sModelFile<-paste(sModelPath,sModel,'/outputData/','FF_RSQ_RSQRM_Japan_v2_19_4_',sModelCurrency,'_',format(sModelDate,"%Y%m%d"),'_AssetData.txt',sep='')
} else if(sModel=='AsiaExJP')
{
sModelFile<-paste(sModelPath,sModel,'/outputData /','FF_RSQ_RSQRM_AsiaExJP_v2_19_6_',sModelCurrency,'_',format(sModelDate,"%Y%m%d"),'_AssetData.txt',sep='')
}
#Read Asset Data File
dfDataHeader<-t(scan(sModelFile,skip=2,nlines=1,what = 'character',sep='|'))
dfData<-read.csv(sModelFile,sep='|',skip=3,header=F,stringsAsFactors=F)
names(dfData)<-dfDataHeader
return(dfData)
}
=============
资产数据| RSQRM_GlobalDev_v2_19_8_EUR 日期| 20140423 RSQID |父母ID |报价货币|住所|交换所国家| ADR |当前价格|本地Mkt上限|名称|返回|特定回报|模型R-Squared |历史差异|模型差异|基础货币Mkt Cap AED || USD | #N / A | #N / A | 0 | 0.272242 | 0 | United Arab Dirham | -0.00525701 | -1.019239e-005 | 0.9999894 | 0.008664313 | 0.01005771 | 0 ARS || USD | #N / A | #N / A | 0 | 0.1249497 | 0 |阿根廷比索| -0.004397333 | 0 | 1 | 0.01426818 | 0.01750348 | 0 AUD || USD | #N / A | #N / A | 0 | 0.9287573 | 0 |澳大利亚元| 0.006424189 | 0 | 1 | 0.01322997 | 0.01398572 | 0 BRL || USD | #N / A | #N / A | 0 | 0.4455243 | 0 |巴西雷亚尔| 0.03908932 | 0 | 1 | 0.01858497 | 0.01901002 | 0 BWP || USD | #N / A | #N / A | 0 | 0.1141982 | 0 |博茨瓦纳普拉| 0.01457977 | 0.01029778 | 0.8950179 | 0.0081137 | 0.008672097 | 0 CAD || USD | #N / A | #N / A | 0 | 0.9057439 | 0 |加拿大元| 0.01092219 | 0 | 1 | 0.007959329 | 0.008564582 | 0 CHF || USD | #N / A | #N / A | 0 | 1.133649 | 0 |瑞士法郎| 0.00140202 | 0 | 1 | 0.003511256 | 0.005111289 | 0 CLP || USD | #N / A | #N / A | 0 | 0.001774098 | 0 |智利比索| -0.03123808 | 0 | 1 | 0.01214774 | 0.01481514 | 0 CNY || USD | #N / A | #N / A | 0 | 0.160308 | 0 |人民币| -0.01323205 | 0 | 1 | 0.008269959 | 0.009692453 | 0 COP || USD | #N / A | #N / A | 0 | 0.0005161191 | 0 | COLOMBIAN PESO | 0.03332853 | 0 | 1 | 0.01231008 | 0.01293377 | 0 EGP || USD | #N / A | #N / A | 0 | 0.1429034 | 0 |埃及镑| -0.01327199 | -0.00800544 | 0.9377586 | 0.01042045 | 0.01099546 | 0 EUR || USD |#N / A |#N / A | 0 | 1.38284 | 0 | EURO | 0 | 0 | 0 | 0 | 0 | 0 GBP || USD | #N / A | #N / A | 0 | 1.6778 | 0 | POUNDS STERLING | 0.01696134 | 0 | 1 | 0.005241998 | 0.005920209 | 0 HKD || USD | #N / A | #N / A | 0 | 0.1289722 | 0 |港元| -0.003935099 | 0.001270294 | 0.9993091 | 0.008515768 | 0.009881006 | 0 HUF || USD | #N / A | #N / A | 0 | 0.004495231 | 0 |匈牙利福林| 0.0242871 | 0 | 1 | 0.01060005 | 0.009236147 | 0 IDR || USD | #N / A | #N / A | 0 | 8.598194e-005 | 0 |印度尼西亚卢比| -0.03087831 | 0 | 1 | 0.01365197 | 0.01479055 | 0 ILS || USD | #N / A | #N / A | 0 | 0.2871667 | 0 |以色列谢克尔| -0.0003501177 | 0 | 1 | 0.006951562 | 0.006442094 | 0 INR || USD | #N / A | #N / A | 0 | 0.01635841 | 0 |印度卢比| -0.03235179 | 0 | 1 | 0.01130393 | 0.01236205 | 0 ISK || USD | #N / A | #N / A | 0 | 0.008922095 | 0 |冰岛克朗| 0.0171473 | 0.03882897 | 0.297565 | 0.04469517 | 0.04829158 | 0 JPY || USD | #N / A | #N / A | 0 | 0.00976686 | 0 |日元| -0.00645864 | 0 | 1 | 0.01881293 | 0.01908195 | 0 KRW || USD | #N / A | #N / A | 0 | 0.0009616939 | 0 |韩元| 0.05476844 | 0 | 1 | 0.009969143 | 0.01028664 | 0 KWD || USD | #N / A | #N / A | 0 | 3.555414 | 0 |科威特第纳尔| -0.002247274 | 0.002172351 | 0.9813095 | 0.006397537 | 0.007210578 | 0 KZT || USD | #N / A | #N / A | 0 | 0.005493779 | 0 |哈萨克斯坦坚戈| -0.004944563 | 0.01499879 | 0.807177 | 0.01728362 | 0.02166266 | 0 LTL || USD | #N / A | #N / A | 0 | 0.4005443 | 0 | Lithuanian Litas | 0.000264883 | 0.0002661943 | 0.1098195 | 4.386074e-006 | 1.170735e-005 | 0 MXN || USD | #N / A | #N / A | 0 | 0.07643005 | 0 | Mexican Nuevo Peso | 0.0002846718 | 0 | 1 | 0.01561729 | 0.01448273 | 0 MYR || USD | #N / A | #N / A | 0 | 0.3061288 | 0 |马来西亚林吉特| 0.01157045 | 0 | 1 | 0.008959501 | 0.009135634 | 0 NAD || USD | #N / A | #N / A | 0 | 0.09418435 | 0 |纳米比亚元| 0.005982637 | -0.001955748 | 0.9904171 | 0.02083048 | 0.01997479 | 0 NOK || USD | #N / A | #N / A | 0 | 0.1668374 | 0 |挪威克朗| 0.009662986 | 0 | 1 | 0.004682287 | 0.004911323 | 0 NZD || USD | #N / A | #N / A | 0 | 0.8582975 | 0 |新西兰元| -0.009660542 | 0 | 1 | 0.01219613 | 0.01205033 | 0 PEN || USD | #N / A | #N / A | 0 | 0.3584124 | 0 | Peruvian Nuevo Sol | 0.009532809 | 0 | 1 | 0.01369225 | 0.01090846 | 0 PHP || USD | #N / A | #N / A | 0 | 0.02233582 | 0 |菲律宾比索| 0.0008690357 | 0 | 1 | 0.008781091 | 0.009171846 | 0 PLN || USD | #N / A | #N / A | 0 | 0.3299508 | 0 |波兰语新兹罗提| -0.003601432 | 0 | 1 | 0.008027087 | 0.007835649 | 0 QAR || USD | #N / A | #N / A | 0 | 0.2746395 | 0 | Qatari Rial | -0.004940689 | 0.0003093481 | 0.9999509 | 0.008670089 | 0.01006616 | 0 RON || USD | #N / A | #N / A | 0 | 0.3093118 | 0 | ROMANIAN LEU(NEW)| 0.0001454353 | 0 | 1 | 0.002584549 | 0.003188807 | 0 RSD || USD | #N / A | #N / A | 0 | 0.01196992 | 0 |塞尔维亚第纳尔| 0.002955198 | 0.002888322 | 0.3149524 | 0.005209823 | 0.005366478 | 0 RSQ00100301 | RSQP001003 | USD |美|美| 0 | 0 | 0 | A.A。 IMPORTING CO INC | 0 | 0 | 0.2278523 | 0.5409994 | 0.6483656 | 0.0388042 RSQ00100401 | RSQP001004 | USD | US | US | 0 | 26.61 | 0 | AAR CORP | 0.03524399 | -0.0009624362 | 0.6713049 | 0.1861986 | 0.1837458 | 761.4265 RSQ00101901 | RSQP001019 | USD | US | US | 0 | 275 | 0 | AFA PROTECTIVE SYSTEMS INC | -0.005258679 | -0.01361179 | 0.546496 | 0.03353066 | 0.04896197 | 38.38115 RSQ00102101 | RSQP001021 | USD | US | US | 0 | 3 | 0 | AFP IMAGING CORP | -0.005258679 | 0.01126492 | 0.2947952 | 1.234856 | 1.125692 | 0.07810013 RSQ00104501W | RSQP001045 | MXN | US | MX | 0 | 460 | 0 | AMERICAN AIRLINES GROUP INC | -0.107383 | -0.1256154 | 0.2745233 | 0.544104 | 0.552039 | 19222.34 RSQ00104504 | RSQP001045 | USD | US | US | 0 | 36.16 | 0 | AMERICAN AIRLINES GROUP INC | -0.03031355 | -0.05283874 | 0.342698 | 0.6602146 | 0.4509373 | 12329.74 RSQ00105001 | RSQP001050 | USD | US | US | 0 | 16.69 | 0 | CECO ENVIRONMENTAL CORP | 0.0177182 | -0.01030165 | 0.4680261 | 0.1776531 | 0.1898829 | 309.8809 RSQ00107201 | RSQP001072 | USD | US | US | 0 | 13.39 | 0 | AVX CORP | 0.04942906 | 0.04780984 | 0.7066215 | 0.04772019 | 0.05692234 | 1628.753 RSQ00107501 | RSQP001075 | USD | US | US | 0 | 55.6 | 0 | PINNACLE WEST CAPITAL CORP | 0.03970087 | -0.02854544 | 0.8831447 | 0.03975214 | 0.0374972 | 4436.935 RSQ00107601 | RSQP001076 | USD | US | US | 0 | 30.13 | 0 | AARON&#39; S INC | -0.02922386 | -0.02090919 | 0.5094755 | 0.07882757 | 0.07039738 | 1568.27 RSQ00107801 | RSQP001078 | USD | US | US | 0 | 38.6 | 0 | ABBOTT LABORATORIES | 0.006312132 | 0.03443837 | 0.4539649 | 0.09144053 | 0.08155435 | 43072.59 RSQ00107801W | RSQP001078 | USD | US | CN | 0 | 38.62 | 0 | ABBOTT LABORATORIES | -0.002148151 | 0.006967425 | 0.2366017 | 0.08802702 | 0.1942208 | 43094.9 RSQ00107802W | RSQP001078 | CHF | US | CH | 0 | 33.75 | 0 | ABBOTT LABORATORIES | -0.02139831 | -0.09285313 | 0.2569895 | 0.4222401 | 0.2419817 | 42693.91 RSQ00108401 | RSQP001084 | USD | US | US | 0 | 0.157 | 0 | WORLDS INC | 0.07596767 | 0.06546307 | 0.4029619 | 1.849886 | 1.528729 | 10.58255 RSQ00109401 | RSQP001094 | USD | US | US | 0 | 21.77 | 0 | ACETO CORP | 0.1782798 | 0.1492193 | 0.6505797 | 0.1856081 | 0.1646115 | 446.7853
答案 0 :(得分:0)
当您调用反应变量时,请像调用函数时一样调用它。
例如,在调用dfAssetData时输出$ assetData,请尝试此...
output$assetData <- renderDataTable(
dfAssetData(),options=list(iDisplayLength = 25)
)
问题可能还有更多,但这是我看到的第一个错误。