I am having an issue using a function I made to determine the chart title of an interactive plot in my shiny app. It works outside my app but not inside
The error: Error in if: argument is of length zero
UI
plotlyOutput("plot"),
column(3,
uiOutput("keysk"), checkboxInput("key1", "1st Key"), checkboxInput("multi", "Multiple", value = F)),
column(3,
uiOutput("keysk2"), checkboxInput("key2", "2nd Key"), checkboxInput("multi2", "Multiple", value = F)),
column(3,
uiOutput("keysk3"), uiOutput("key3rdbox"), checkboxInput("multi3", "Multiple", value = F))
Server
output$plot <- renderPlotly({
*tsibble of your own*() %>% autoplot()
+ labs(title =
titlefinder(key1= input$key1, key2 =input$key2, key3=input$key3, keysk= input$keysk, keysk2=input$keysk2, keysk3=input$keysk3) )
})
output$keysk = renderUI({
req(length(keyvar() >0) )
req(input$key1 == T)
file_to_read <- input$file
selectizeInput("keysk", "Key1" choices = as.list( unique(*Your Tsibble*()[key_vars(*Your Tsibble*())[1]]) ) , multiple = input$multi)
})
output$keysk2 = renderUI({
req(length(keyvar() >1) )
req(input$key2 == T)
file_to_read <- input$file
selectizeInput("keysk2", "Key2", choices = as.list( unique(*Your Tsibble*()[key_vars(*Your Tsibble*())[2]]) ) , multiple = input$multi2)
})
output$keysk3 = renderUI({
req(length(keyvar() >2) )
req(input$key3rdbox == T)
file_to_read <- input$file
selectizeInput("keysk3", "Key3", choices = as.list( unique(*Your Tsibble*()[key_vars(*Your Tsibble*())[3]]) ) , multiple = input$multi3)
})
output$key3rdbox = renderUI({
file_to_read <- input$file
checkboxInput("key3rdbox", "3rd Key")
})
Set Up to test outside app:
input <- c()
input <- as.list(input)
input$keysk <- "New South Wales"
input$keysk2 <- "Liquor retailing"
input$keysk3 <- "Liquor retailing"
input$key1 <- F
input$key2 <- F
input$key3 <- F
Function:
titlefinder <- function(key1, key2, key3, keysk, keysk2, keysk3){
if(key1==T & key2==F & key3==F){title = keysk}
if(key1==T & key2==T & key3==F){title = paste(keysk, keysk2)}
if(key1==T & key2==T & key3==T){title = paste(keysk, keysk2, keysk3)}
if(key1==F & key2==T & key3==F){title = paste(keysk2)}
if(key1==F & key2==T & key3==T){title = paste(keysk2, keysk3)}
if(key1==F & key2==F & key3==T){title = paste(keysk3)}
if(key1==F & key2==F & key3==F){title = ""}
return(title)
}
Example use outside shiny
input$keysk <- "New South Wales"
input$keysk2 <- "Liquor retailing"
input$keysk3 <- "Liquor retailing"
input$key1 <- T
input$key2 <- T
input$key3 <- F
*Your own tsibble* %>% autoplot() + labs(title = titlefinder(input$key1, input$key2, input$key3, input$keysk1, input$keysk2, input$keysk3) )
Example output / Desired output in shiny
[1] "New South Wales Liquor retailing"
Can anyone explain why this will not work once I put it into my shiny app? (can provide more detail about app code if necessary)