取自this问题,我想知道如何以闪亮的方式显示dy_graph列表对象。下面的代码创建了它,但是我不是html方面的专家,阅读htmltools手册无济于事。基本上,我需要更改此部分htmltools::browsable(htmltools::tagList(dy_graph))以便在Shiny中进行渲染。

# create the time series
temperature <- ts(frequency = 12, start = c(1980, 1),
              data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5,
                       25.2, 26.5, 23.3, 18.3, 13.9, 9.6))
rainfall <- ts(frequency = 12, start = c(1980, 1),
           data = c(49.9, 71.5, 106.4, 129.2, 144.0, 176.0,
                    135.6, 148.5, 216.4, 194.1, 95.6, 54.4))

# create a list of dygraphs objects
library(dygraphs)
library(htmltools)
dy_graph <- list(
  dygraphs::dygraph(temperature, group="temp_rain", main="temperature"),
  dygraphs::dygraph(rainfall, group="temp_rain", main="rainfall")
)  # end list

# render the dygraphs objects using htmltools
htmltools::browsable(htmltools::tagList(dy_graph))


编辑:请查看@SBista的答案。 r - 带有htmltools的dygraphs列表-LMLPHP

最佳答案

您可以使用uiOutputrenderUI进行操作。您可以执行以下操作:

library(shiny)
library(dygraphs)

ui <- fluidPage(

  uiOutput("dygraph")
)


server <- function(input, output)
{

  output$dygraph <- renderUI({
    # create the time series
    temperature <- ts(frequency = 12, start = c(1980, 1),
                      data = c(7.0, 6.9, 9.5, 14.5, 18.2, 21.5,
                               25.2, 26.5, 23.3, 18.3, 13.9, 9.6))
    rainfall <- ts(frequency = 12, start = c(1980, 1),
                   data = c(49.9, 71.5, 106.4, 129.2, 144.0, 176.0,
                            135.6, 148.5, 216.4, 194.1, 95.6, 54.4))

    dy_graph <- list(
      dygraphs::dygraph(temperature, group="temp_rain", main="temperature"),
      dygraphs::dygraph(rainfall, group="temp_rain", main="rainfall")
    )

    tagList(dy_graph)
  })

}

shinyApp(ui = ui, server = server)

07-24 13:15