2017-12-20 4 views
0

Ich habe Probleme in R-Codierung eine glänzende App. Wenn ich die Funktion in einem separaten Skript benutze, das nicht glänzend ist, erhalte ich das Plot, wenn ich das Plot separat hinzufüge und das Dataframe ausgibt. Entschuldigung für die Abkürzungen und den langen Code. Derzeit arbeite ich an einem Projekt. Wenn es jedoch glänzend ist, ist der Fehler der folgende:benutzerdefinierte Funktion -> Datenrahmen -> reaktiv -> Plot -> ERROR (Null-Länge Eingänge können nicht mit denen von nicht-Null-Länge gemischt werden)

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> 

Was ist das Problem?

Bibliothek (glänzend)

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')}) 

Antwort

0

Ihr Beispiel ist leider nicht reproduzierbar, please take a notice of it.

Ohne jede Art und Weise zum Ausführen des Codes ich annehmen, dass es ein Problem in plotly Teil ist, versuchen Sie dies aus -> ich habe Zeichen hinzugefügt ~ vor x und y Variablen

output$plot2 <- renderPlotly({plot_ly(obs2(), x = ~timed, y = ~LO, type = 'scatter')}) 

Wenn dies versuchen, wird nicht funktionieren Drucken Sie in der Konsole obs2, wenn Sie tatsächlich die Daten von der Funktion SL in Shiny:

obs2 <- reactive({ 
data <- SL(input$SPI, input$SLO, input$BR, input$RPI, input$AGFS,input$EC,input$ATFB) 
print(data)}) 
erhalten