我正在使用Shiny的renerUI按照this问题的指示动态创建UI对象。
我收到以下错误
Error in if (!grepl(pattern, text)) return(text) :
argument is of length zero
阅读this后我知道问题就在这一行
# Convert the list to a tagList
do.call(tagList, plot_output_list)
但我正在做的解决方案建议完全正确。 感谢任何帮助。
代码
Server.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)
})
})
ui.r
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")
))
答案 0 :(得分:0)
我猜一个问题是plot_output_list
不应该按字符串编制索引,而应按数字编制索引,即plot_output_list[[symbol]] <- ...
应为plot_output_list[[i]] <- ...; i <- i + 1
如果这不起作用,请在遇到错误后立即尝试运行traceback()
,以便我们可以看到错误的来源。