Renderização em 3D brilhante
Estou tentando renderizar dinamicamente vários gráficos em uma guia (melhor se isso puder ser feito em várias guias). Depois de alguma pesquisa, encontrei estepostar é muito útil Mas no meu caso, o número de plotagens é determinado pelo arquivo CSV carregado. Então eu acho que a pergunta é como ligarplotInput()$n_plot
em um loop for? Agradeço todas as sugestões!
Neste momento, eu sou capaz de criar múltiplos<div>s
chamandorenderUI
.
<div id="plot1" class="shiny-plot-output" style="width: 800px ; height: 800px"></div>
<div id="plot2" class="shiny-plot-output" style="width: 800px ; height: 800px"></div>
Mas eu não poderia chamar adequadamente a função reativa nofor (i in 1:plotInput()$n_plot)
ciclo. A mensagem de erro é:
Error in .getReactiveEnvironment()$currentContext() :
Operation not allowed without an active reactive context.
Server.R shinyServer(function(input, output) {
### This is the function to break the whole data into different blocks for each page
plotInput <- reactive({
get_the_data()
return (list("n_plot"=n_plot, "total_data"=total_data))
})
##### Create divs######
output$plots <- renderUI({
plot_output_list <- lapply(1:plotInput()$n_plot, function(i) {
plotname <- paste("plot", i, sep="")
plotOutput(plotname, height = 280, width = 250)
})
do.call(tagList, plot_output_list)
})
# Call renderPlot for each one.
####This is the place caused the error##
for (i in 1:plotInput()$n_plot) {
local({
my_i <- i
plotname <- paste("plot", my_i, sep="")
output[[plotname]] <- renderPlot({
hist(plotInput()$total_data[i])
})
})
}
})
AtualizarSe eu envolver o loop for dentro de umreactive
função e chame-o como parte derenderUI
, o loop funciona, mas o gráfico está ausente, acho que é porque umrenderUI
criar apenas tags HTML, ele não atribuirá imagens às tags geradas.
output$plots <- renderUI({
plot_output_list <- lapply(1:plotInput()$n_plot, function(i) {
plotname <- paste("plot", i, sep="")
plotOutput(plotname, height = 280, width = 250)
})
do.call(tagList, plot_output_list)
plot_concent()
})
# Call renderPlot for each one.
####This is the place caused the error##
plot_concent<-reactive({
for (i in 1:plotInput()$n_plot) {
local({
my_i <- i
plotname <- paste("plot", my_i, sep="")
output[[plotname]] <- renderPlot({
hist(plotInput()$total_data[i])
})
})
}
})