我正在使用SCperf软件包来开发R Shiny应用程序,以进行供应链分析。 首先,我有兴趣将Wagner-whitin动态批量大小模型实现为r闪亮的应用程序。但是,使用SCPerf手册中的以下示例,我遇到了一个奇怪的错误,我得到了正确的解决方案:
x <- c(3,2,3,2)
a <- 2
h <- 0.2
WW(x,a,h,method="backward")
但是,当将其嵌入R Shiny服务器环境中并用滑块控制所有参数时,会产生错误的解决方案。
在我的代码下面:
sidebarPanel(
sliderInput("x1",label="period 1 demand",min=0, max=10,value=1,step=0.1),
sliderInput("x2",label="period 2 demand",min=0, max=10,value=1,step=0.1),
sliderInput("x3",label="period 3 demand",min=0, max=10,value=1,step=0.1),
sliderInput("x4",label="period 4 demand",min=0, max=10,value=1,step=0.1),
sliderInput("a",label="Setup costs",min=0,max=10,value=0,step=1),
sliderInput("h",label="Holding costs",min=0,max=1,value=0.2,step=0.1)
)
mainPanel(
dataTableOutput("ww")
)
和
library(SCperf)
library(DT)
wwmod <- reactive({
x <- c(as.numeric(input$x1),as.numeric(input$x2),as.numeric(input$x3),as.numeric(input$x4)) # demands
a <- as.numeric(input$a)
hold <- as.numeric(input$h)
res <- data.frame(WW(x,a,hold)[3],method="backward")
return(res)
})
output$ww <- renderDataTable({
wwmod()
})
有人知道这是什么原因吗?是我的代码还是其他?
非常感谢。