2017-08-09 1 views
0

Ich habe diese glänzende App, wo ich mehrere dygraphs plotten. Leider weiß ich nicht, wie viele Plots dort geplottet werden. Es kann von Zeit zu Zeit variieren. Also kam ich mit uiOutput und renderUI zum Erstellen einer App, die auf die Anzahl der Plots reagiert. Siehe https://shiny.rstudio.com/articles/dynamic-ui.htmldygraphs Legende außerhalb Grundstück in glänzenden App für mehrere Grundstücke

Jetzt habe ich die Legende von jedem dygraph außerhalb des jeweiligen Grundstück zeigen wnat wie es hier gezeigt: Is there a way to add legend next to a dygraph in R, not exactly on the plot?

Mein Problem ist jetzt, dass die <div> Elemente der Legende nicht die gleiche Höhe wie die, die haben der Grundstücke.

Mein Code ist:

UI:

library(dygraphs) 
shinyUI(fluidPage(
titlePanel("Simple example"), 
sidebarLayout(
    sidebarPanel(), 
    mainPanel(
    fluidRow(column(10, uiOutput("graphs")), 
      column(2, uiOutput("legends"))) 
    ) 
) 
)) 

Server:

library(dygraphs) 
library(xts) 

shinyServer(function(input, output, session) { 

# load xts sample data 
data("sample_matrix") 
sample.xts <- as.xts(sample_matrix) 

output$graphs <- renderUI({ 
plot_output_list <- lapply(1:3, function(i) { 
    dygraphOutput(paste0('div_graph_', i)) 
}) 
}) 

output$legends <- renderUI({ 
legend_output_list <- lapply(1:3, function(i) { 
    htmlOutput(paste0("div_legende",i), height = "400px") 
}) 
}) 

# do the plotting 
lapply(1:3, function(i) { 
    output[[paste0('div_graph_', i)]] <- renderDygraph({ 
    dygraph(sample.xts[,i],main=i)%>% 
    dyLegend(labelsDiv = paste0("div_legende",i), show = "always") 
    }) 
}) 
}) 

Das auf diesem Grundstück führt, wo man die Legenden aller drei Parzellen sehen können direkt miteinander geklebt werden . Ich möchte, dass sie in ihrer jeweiligen Handlung richtig liegen.

sample plot with legend

Antwort

0

ich habe es. Erstellen Sie eine plotOutput und eine leere plot macht den Trick:

Ui bleibt gleich. Server:

library(dygraphs) 
library(xts) 

shinyServer(function(input, output, session) { 

data("sample_matrix") 
sample.xts <- as.xts(sample_matrix) 

output$graphs <- renderUI({ 
    plot_output_list <- lapply(1:3, function(i) { 
    dygraphOutput(paste0('div_graph_', i)) 
}) 
}) 

output$legends <- renderUI({ 
legend_output_list <- lapply(1:3, function(i) { 
    plotOutput(paste0("div_legende",i), height = "400px") 
}) 
}) 

lapply(1:3, function(i) { 
    output[[paste("div_legende",i)]] <- renderPlot(
    plot(1,1,type="n",xaxt="n",yaxt="n",ylab="",xlab="",bty="n"), 
    height = "400px" 
) 
    output[[paste0('div_graph_', i)]] <- renderDygraph({ 
    dygraph(sample.xts[,i],main=i)%>% 
    dyLegend(labelsDiv = paste0("div_legende",i), 
      show = "always") 
    }) 
}) 
}) 
Verwandte Themen