在Rmarkdown中嵌入Plotly图形,嵌入在闪亮的应用程序中

时间:2016-06-21 13:12:19

标签: r shiny r-markdown plotly shinydashboard

我试图制作一个闪亮的应用程序,根据用户输入,它将在浏览器中显示许多预编译的html文件(由Rmarkdown文件生成)中的一个。我已经完成了这项工作,但我也想在这些html文件中加入图表,这些图表也将显示在闪亮的应用程序中。

情节图表在html文档中显示得很好。 html文档像以前一样在闪亮的应用程序中嵌入很好,但是只有一个空白区域,其中应该是情节图表。如果使用ggplot简单地生成图表,则它没有问题。

有没有办法让情节图表出现在闪亮的应用程序中,就像静态R图一样?

示例降价和闪亮代码如下。

example.rmd

---
title: "example markdown"
output: html_document
---

You can also embed plots, for example:

```{r, echo=FALSE, warnings = FALSE}
suppressPackageStartupMessages(library(ggplot2))
suppressPackageStartupMessages(library(plotly))
suppressPackageStartupMessages(library(ggthemes))

plot_raw <- ggplot(cars, aes(x = speed, y = dist)) +
  geom_point() +
  theme_hc()

p <- ggplotly(plot_raw)
p
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.  

app.R

library(shiny)
library(shinydashboard)
library(ggplot2)
library(reshape2)
library(dplyr)

#### Server Code ####

server <- function(input, output) {

  output$test <- renderUI(includeHTML("example.html"))

}

#### UI Code ####


header <- dashboardHeader(title = "plotly test")

sidebar <- dashboardSidebar(

  sidebarMenu(id="menu1",

              menuItem("tab 1", 
                       tabName = "tab1", 
                       icon = icon("desktop")),

              menuItem("tab 2", 
                       tabName = "tab2", 
                       icon = icon("dashboard")),

              conditionalPanel(
                condition = "input.menu1 == 'tab2'",
                selectInput("choice", "Select from choices", 
                            choices = c(1,2,3))
                )
              )
  )

body <- dashboardBody(


  conditionalPanel(
    condition = "input.menu1 == 'tab2'",
    fluidPage(

      htmlOutput('test')

    )
  )
  )

ui <- dashboardPage(header, sidebar, body)

shinyApp(ui = ui, server = server)

0 个答案:

没有答案
相关问题