1

我在使用我制作的函数来确定闪亮应用程序中交互式绘图的图表标题时遇到问题。它可以在我的应用程序之外工作,但不能在我的应用程序内部

错误: Error in if: argument is of length zero

用户界面

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

服务器

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

设置以测试外部应用程序:

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

功能:

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

使用外部闪亮的示例

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

示例输出/闪亮的所需输出

[1] "New South Wales Liquor retailing"

谁能解释为什么一旦我将它放入闪亮的应用程序中这将不起作用?(如有必要,可以提供有关应用程序代码的更多详细信息)

4

0 回答 0