I have a shiny application which is running fine on the browser, and is generating errors when I put it on my server (pluto.coe.fsu.edu/rdemos).
Here is the core part of the code:
inputPanel(
selectInput("tails1", label = "Which tails",
choices = c("Upper tail: Pr(z < Z)"="upper",
"Lower tail: Pr(Z < z)"="lower",
"Both tails: Pr(Z <-z or z< Z)"="both",
"Middle: Pr(-z < Z < z)"="middle"),
selected = "both"),
numericInput("p", label = "Probability of shaded region:", value=0.05, min=0, max=1)
)
renderPlot({
pp <- input$p
q <- switch(input$tails1,
upper=qnorm(1-pp),
lower=qnorm(pp),
both=qnorm(1-pp/2),
middle=qnorm(.5+pp/2))
xl <- round(max(3,ceiling(abs(q)+.5)),1)
curve(dnorm(x),main=paste("Probability of shaded region = ",round(pp,3)),
sub=paste("z = ",round(q,3)),
xlim = c(-xl,xl),yaxt="n",cex=3,cex.lab=2,cex.main=2,ylab="",xlab="z")
})
This works on my desktop in RStudio (Running R 4.3.2 and shiny 1.8.0), but is generating an error when running on the server (also running R 4.3.2 and shiny 1.8.0).
On the sever, the relevant parts of the log file are:
Output created: /tmp/RtmpFeD6p9/file1ba53c5289ea58/NormalCalculator.html
Warning: Error in switch: EXPR must be a length 1 vector
170: renderPlot [<text>#14]
168: func
128: drawPlot
114: <reactive:plotObj>
98: drawReactive
85: renderFunc
84: output$out7f5ebc68b3bd0d95
3: <Anonymous>
1: rmarkdown::run
The issue seems to be that the initial return value for the input from the selectInput()
widget is not the value of the selected
argument, quite possibly NULL
In particular, if I edit the renderPlot()
function to include a specific NULL check, it works on the server:
mde <- input$tails
if (length(mde) != 1L) mde <- "both"
p <- switch(mde,
So something is not getting initialized properly on my shiny server.