0

我正在使用 Shiny 的 renerUI 按照这个问题的说明动态创建 UI 对象。

我收到以下错误

Error in if (!grepl(pattern, text)) return(text) : 
  argument is of length zero

读完这篇我知道问题出在这条线上

# Convert the list to a tagList
do.call(tagList, plot_output_list)

但我正在按照解决方案的建议做。感谢任何帮助。

编码

服务器.r

shinyServer(function(input, output) {

    # Create an environment for storing data
    symbol_env <- new.env()

    output$plots <- renderUI({

        if (input$goButton == 0) 
            return()

        if (loaded_index != input$chosen_index) {

            # ... alot of code to generate data.frames and plots 

            output[["summary"]] <- renderPlot(grid.arrange(g1,g2,g3,g4,g5,nrow=1))

            for (i in 1:length(results)) {
                # Need local so that each item gets its own number. Without it, the value
                # of i in the renderPlot() will be the same across all instances, because
                # of when the expression is evaluated.
                local({
                    my_i <- i
                    plotname <- object_name("plot", names(results[my_i]))
                        output[[plotname]] <- renderPlot({
                            showme_plot(results[[names(results[my_i])]]$data , period = DEFAULT_TIME_PERIOD)})

                    tablename <- object_name("table", names(results[my_i]))
                        output[[tablename]] <- renderTable({
                            make_summary(names(results[my_i]))})
                    })
            }
        }

        plot_output_list <- list()

        # Graphical Summary     
        plot_output_list[["summary"]] <- tags$div(class="summary" , plotOutput("summary")) 

        # The List
        for (symbol in names(results))
            plot_output_list[[symbol]] <- 
                tags$div(class = "container" ,
                    tags$div(class = "name"  , name(symbol)),
                    tags$div(class = "stats" , tableOutput(object_name("table", symbol))) , 
                    tags$div(class = "plot"  , plotOutput(object_name("plot", symbol), height = 530)))

        print("Plot structure defined")

        # Convert the list to a tagList
        do.call(tagList, plot_output_list)
    })
})

用户界面

require(shinyIncubator) 
shinyUI(
    bootstrapPage(
        tags$script(src = "keyboard_scroller.js") , 
        tags$link(rel="stylesheet" , type="text/css" , href="custom.css") ,
        actionButton("goButton", "Go!") , 
        selectInput("chosen_index" , "INDEX: " , list("A" = '1' , "B" = '2')) ,
        # This is the dynamic UI for the plots
        uiOutput("plots")
))
4

1 回答 1

0

我想一个问题是plot_output_list不应该用字符串索引,而是用数字索引,即plot_output_list[[symbol]] <- ...应该是plot_output_list[[i]] <- ...; i <- i + 1

如果这不起作用,traceback()请尝试在遇到错误后立即运行,以便我们查看错误来自何处。

于 2013-06-11T00:14:32.293 回答