I am having a similar problem where if I increase the dimension of a reactive array using a numeric input and it flashes up an error message "Warning: Error in <-: number of items to replace is not a multiple of replacement length" before then re-exicuting and working.
I would like to have my code check whether the dependencies are ready do I don't get this error message and I have tried a lot of things to do this but cant seem sort out the issue. How would you suggest checking for these dependencies?
shinyServer(
function(input, output) {
outcomes <- reactive({
input$numOutcomes
})
ncovs <- reactive({
input$numCovs
})
M <- reactive({
input$numSamp
})
output$sliders1 <- renderUI({
lapply(1:(outcomes()-1), function(i) {
sliderInput(paste0("mu", i), label = h4(withMathJax('\\(\\mu_{',(i+1),'0}\\)')),
min = -10, max = 10, value = -4, step= 0.1, animate = TRUE)
})
})
output$sliders2 <- renderUI({
lapply(1:(outcomes()-1), function(i) {
sliderInput(paste0("sigma", i), label = h4(withMathJax('\\(\\sigma_{',(i+1),'0}\\)')),
min = 0, max = 3, value = 0.1, step= 0.05, animate = TRUE)
})
})
output$covranges <- renderUI({
lapply(1:ncovs(), function(i) {
sliderInput(paste0("covrange", i), label = h4(withMathJax('\\(x_{',i,'}\\)')),
min = -10, max = 10, value = c(0,4))
})
})
#plots
Create_mu <- reactive({
mu <- array(0,dim=c((outcomes()-1),(ncovs()+1)))
for(i in 1:(outcomes()-1)){
mu[i,1] <- input[[paste0("mu",i)]]
}
mu
})
#mu[2:(r-1),] = 0
Create_sigma <- reactive({
sigma <- array(0.5,dim=c((outcomes()-1),(ncovs()+1)))
for(i in 1:(outcomes()-1)){
sigma[i,1] <- input[[paste0("sigma",i)]]
}
sigma
})
#sigma[2:(r-1),] = 0.5
Create_ranges <- reactive({
ranges <- array(dim=c(ncovs(),2))
for(i in 1:ncovs()){
ranges[i,] <- input[[paste0("covrange",i)]]
}
ranges
})
output$thetas <- renderPlot({
use_r <- input$numOutcomes
use_C <- input$numCovs
use_M <- input$numSamp
use_mu <- Create_mu()
use_sigma <- Create_sigma()
use_ranges <- Create_ranges()
theta_plot(r=use_r,C=use_C,M=use_M,mu=use_mu,sigma=use_sigma,ranges=use_ranges)
})