2017-04-19 52 views
1

我从this question了解到,您可以将shinyApp选项设置为showcase mode,以便在用户与应用程序交互时可视化(即突出显示)Shiny代码的哪些部分正在执行。如何在rmarkdown/knitr交互式Shiny文档中使展示模式工作?

但是,当我尝试将这个应用到使用knitr/R markdown的交互式Shiny文档时,展示的代码未能显示出来。

如何使showcase mode在交互式文档中工作?

例子:

--- 
title: "Showcase Mode Doesn't Work in knitr" 
output: html_document 
runtime: shiny 
--- 

See, look, no highlatable code shows up with the app: 

```{r, echo=FALSE} 
library(shiny) 
ui <- fluidPage(
    textInput(inputId = 'textin', label = ''), 
    textOutput(outputId = 'textout') 
) 
server <- function(input, output){ 
    output$textout <- renderText({input$textin}) 
    } 
shinyApp(ui = ui, server = server, options = list(display.mode='showcase')) 
``` 
+0

http://rmarkdown.rstudio.com/authoring_shiny.html –

+0

Hi @Petr。该文件的哪一部分回答了我的问题? – theforestecologist

+0

@Petr我知道如何在rmarkdwon中嵌入应用程序。我的示例应用程序做得很好。但是,我无法将展示的代码显示在文档中。这个问题在您的链接中似乎没有得到解决。谢谢。 – theforestecologist

回答

2

,你不能为markdown文件是简单指定showcase mode的原因 - 它不存在。

Knitr(和Rmarkdown文档)在html页面中预先呈现输出结果。在交互式html文档中,它将预渲染“渲染对象”的所有输出,并根据输入的指定在输入之间进行切换(如果我理解了今年Rconf上的Yihui Xie的解释)。

鉴于在shiny中,输出是动态生成的,因为有一个后端(您的计算机,服务器等)在输入发生更改时运行代码。这就是为什么你可以打开showcase,看看那些事情正在改变,并正在动态地重新运行。