0
Shiny AppをRコード化する際に問題があります。私は光沢を使用していない別のスクリプトで関数を実行するときにプロットを個別に追加し、データフレームの出力を得る場合は、プロットを取得します。頭字語と長いコードには申し訳ありません。現在、プロジェクトに取り組んでいます。ただし、一度光沢があると、エラーは次のようになります。カスタム関数 - > dataframe - > reactive - > plot - > ERROR(長さゼロの入力は長さがゼロ以外のものと混在することはできません)
Warning: Error in mapply: zero-length inputs cannot be mixed with those of non-zero length
Stack trace (innermost first):
99: mapply
98: AddMonths
97: SL [#31]
96: <reactive:obs2> [#7]
85: obs2
84: is.data.frame
83: plot_ly
82: "plotly"::"ggplotly" [#24]
81: func
80: origRenderFunc
79: output$plot2
4: <Anonymous>
3: do.call
2: print.shiny.appobj
1: <Promise>
問題点は何ですか?
ライブラリ(光沢)
ui <- navbarPage("name", tabPanel("name2",sidebarLayout(
sidebarPanel(numericInput("AI", "name3", min = 0, max = 100,
value = c(25, 40)), sliderInput("AGFS", "name4", min = 0, max = 200000,
value = 57000, pre = "£"), selectInput("SPI", "SPIType",
list("Plan 1", "Plan 2", "No"), selected = NULL, multiple = FALSE,selectize = TRUE, width = NULL, size = NULL),
numericInput("SLO", "SLOType", min = 0, max = 100000, value = 15000),
sliderInput("EC", "ECType:", min = 0, max = 100, value = 11, post = "%"),
), mainPanel("the results will go here")))
,tabPanel("NIT", sidebarLayout(
sidebarPanel(sliderInput("ATFB", "ATFBtype:", min = -60000, max = 0, value = -1180.8, pre = "£"),
sliderInput("TB", "TBtype:", min = 0, max = 100000, value = 656, pre = "£")),
mainPanel("the results will go here")))
,tabPanel("name5", sidebarLayout(
sliderInput("BR", "BaseRateType:", min = 0, max = 10, value = 0.25,step = 0.05, post = "%"), sliderInput("RPI", "RPI:", min = 0, max = 10, value = 3.1, step = 0.1, post = "%")), mainPanel(plotlyOutput("plot2"))))
SL <- function(SPI, SLO, BR, RPI, AGFS,EC,ATFB){
Deb = 17775
DebMonthly = Deb/12
Deb2 = 21000
Deb2Monthly = RepaymentThresholdPlan2Annual/12
ECTotal= AGFS*EC
AGFSBT = AGFS+ATFB-ECTotal
obs = data.frame(timed=c(Sys.Date()), LO = c(SLO), iint = c(0), total = c(0), R1 = c(0))
add.months= function(date,n){ seq(date, by = paste (n, "months"), length = 2)[2]}
if (SPI == "Plan 1"){
R= ((AGFSBT - Deb)*0.09)/12
if (min(1+BR, RPI) == RPI){
smallr <- RPI
}else{
smallr <- min(1+BR, RPI)}
smallr
N = n.period(((1 + smallr)^(1/12) - 1), -SLO, 0, R, 0)+2
obs[2,2]= SLO
obs[2,1] = AddMonths((obs[1,1]),1)
for (i in 2:N) {
obs[i,5]= -R}
for (i in 3:N) {
obs[i,1] = AddMonths((obs[i-1,1]),1)
obs[2,3]= SLO* ((1 + smallr)^(1/12) - 1)
obs[2,4]= obs[2,2]+obs[2,3]
obs[i,2] = obs[i-1,4]+obs[i,5]
obs[i,3]= obs[i,2]* ((1 + smallr)^(1/12) - 1)
obs[i,4]= obs[i,2]+obs[i,3]
}
} else if(SPI == "Plan 2"){
R= ((AGFSBT - Deb2)*0.09)/12
if(AGFS<=21000){
smallr = RPI
}else if(AGFS>=21000.01 && AGFS<=41000){
smallr = RPI+(((AGFS-21000.01)/21000.01)*0.03)/((41000-21000)/21000)*100
}else if (AGFS>=41000.01){
smallr = (RPI+0.03)}
for (i in 2:N) {
obs[i,5]= -R}
for (i in 3:N) {
obs[i,1] = AddMonths((obs[i-1,1]),1)
obs[2,3]= SLO* ((1 + smallr)^(1/12) - 1)
obs[2,4]= obs[2,2]+obs[2,3]
obs[i,2] = obs[i-1,4]+obs[i,5]
obs[i,3]= obs[i,2]* ((1 + smallr)^(1/12) - 1)
obs[i,4]= obs[i,2]+obs[i,3]
}}
return(obs)
}
server <- function(input, output) {
obs2 <- reactive({SL(input$SPI, input$SLO, input$BR, input$RPI, input$AGFS,input$EC,input$ATFB)})
output$plot2 <- renderPlotly({plot_ly(x = obs2()$timed, y = obs2()$LO, type = 'scatter')})