情节html嵌入闪亮

时间:2019-03-06 20:54:54

标签: html r shiny plotly

我使用plotly生成了一些图并将其保存为离线html(我不想实时生成它们,因为在后台生成它们会花费很长时间)。以下是从plotly网站获取的两个图表,我将它们另存为html。

#Graph 1
Animals <- c("giraffes", "orangutans", "monkeys")
SF_Zoo <- c(20, 14, 23)
LA_Zoo <- c(12, 18, 29)
data <- data.frame(Animals, SF_Zoo, LA_Zoo)

p <- plot_ly(data, x = ~Animals, y = ~SF_Zoo, type = 'bar', name = 'SF Zoo') %>%
  add_trace(y = ~LA_Zoo, name = 'LA Zoo') %>%
  layout(yaxis = list(title = 'Count'), barmode = 'group')

htmlwidgets::saveWidget(p, file="zoo.html")


#Graph 2
x <- c('Product A', 'Product B', 'Product C')
y <- c(20, 14, 23)
text <- c('27% market share', '24% market share', '19% market share')
data <- data.frame(x, y, text)

p <- plot_ly(data, x = ~x, y = ~y, type = 'bar', text = text,
             marker = list(color = 'rgb(158,202,225)',
                           line = list(color = 'rgb(8,48,107)',
                                       width = 1.5))) %>%
  layout(title = "January 2013 Sales Report",
         xaxis = list(title = ""),
         yaxis = list(title = ""))
htmlwidgets::saveWidget(p, file="product.html")

我写了一些shiny代码,它们可以显示来自Rmarkdown的html输出,但不能显示我从上面的plotly生成的html。请注意,selectInput()中的第一个选择(样本)是我从默认Rmarkdown html生成的内容,并且可以正常工作。我还生成了多个rmarkdown html,并且也可以在shiny应用中的html之间切换,但不能为plotly html切换。

ui= fluidPage(
  titlePanel("opening web pages"),
  sidebarPanel(
    selectInput(inputId='test',label=1,choices=c("sample","zoo","product"))
  ),
  mainPanel(
    htmlOutput("inc")
  )
)
server = function(input, output) {
  getPage<-function() {
    return(includeHTML(paste0("file:///C:/Users/home/Documents/",input$test,".html")))
  }
  output$inc<-renderUI({getPage()})
}
shinyApp(ui, server)

1 个答案:

答案 0 :(得分:0)

您可以为此使用iframe-也可以查看Column<b'1 AS `A`'> 1 AS `A`

addResourcePath