【问题标题】:embed shiny app into Rmarkdown html document将闪亮的应用程序嵌入到 Rmarkdown html 文档中
【发布时间】:2020-10-21 19:36:34
【问题描述】:

我能够创建一个 Rmarkdown 文件,并且我正在尝试将一个闪亮的应用程序嵌入到 html 输出中。如果我运行 Rmarkdown 文件中的代码,交互式图表会显示。但在 html 输出中它只显示一个空白框。有人可以帮忙解决吗?

运行Rmarkdown文件中的代码:

在html输出中:

我的 Rmarkdown 文件(请自行在末尾添加三个代码符号,我在这里做不到):

        ---
        title: "Data Science - Tagging"
        pagetitle: "Data Science - Style Tagging"
        author: 
          name: "yyy"
        params:
          creation_date: "`r format(Sys.time(), c('%Y%m%d', '%h:%m'))`"
        runtime: shiny
        ---

        ```{r plt.suppVSauto.week.EB, out.width = '100%'}

        data <- data.frame(BclgID = c('US','US','US','UK','UK','UK','DE','DE','DE'), 
                           week = as.Date(c('2020-06-28', '2020-06-21', '2020-06-14', '2020-06-28', '2020-06-21', '2020-06-14', '2020-06-28', '2020-06-21', '2020-06-14')), 
                           value = c(1,2,3,1,2,2,3,1,1))

        shinyApp(
  
          ui <- fluidPage(
  
          radioButtons(inputId = 'BclgID', label = 'Catalog', 
                       choices = type.convert(unique(plot$BclgID), as.is = TRUE),
                       selected = 'US'),
          plotOutput("myplot")
          ),


          server <- function(input, output) {
  
            mychoice <- reactive({
              subset(data, BclgID %in% input$BclgID)
            })
  
            output$myplot <- renderPlot({
              if (length(row.names(mychoice())) == 0) {
                  print("Values are not available")
            }
              p <- ggplot(mychoice(), aes(x=as.factor(week), y=value)) + 
                geom_line() + 
                labs(title = "test",
                     subtitle = "",
                     y="Value", 
                     x ="Date") +
                theme(axis.text.x = element_text(angle = 90)) +
                facet_wrap( ~ BclgID, ncol = 1)
              print(p)
  
            }, height = 450, width = 450)
  
        }
  
        )

【问题讨论】:

    标签: html r shiny r-markdown


    【解决方案1】:

    我看到这是很久以前问过的,所以你可能已经继续前进了,但我遇到了同样的问题,这是最先出现的,所以我会回答它以防其他人遇到这个问题。

    我在这个页面上找到了答案: https://community.rstudio.com/t/embedding-shiny-with-inline-not-rendering-with-html-output/41175

    它的缺点是闪亮的文档需要运行而不是渲染。而不是调用:

    &gt;rmarkdown::render("filename.rmd")

    我们需要调用:

    &gt;rmarkdown::run("filename.rmd")

    如果您在 Rstudio 中,在 RMD 中使用闪亮时,“编织”功能似乎从渲染变为运行。

    【讨论】:

      猜你喜欢
      • 2017-12-22
      • 2016-02-03
      • 2019-01-08
      • 2018-02-18
      • 2015-09-25
      • 2015-06-26
      • 1970-01-01
      • 2014-08-09
      • 1970-01-01
      相关资源
      最近更新 更多