【问题标题】:create R markdown table of content experience in shiny在 Shiny 中创建 R markdown 目录体验
【发布时间】:2021-12-02 10:39:48
【问题描述】:

我想为闪亮的应用创建目录体验。

所以也许是这样一个闪亮的应用程序:

library(shiny)
library(shinydashboard)

ui <- dashboardPage(
  dashboardHeader(),
  dashboardSidebar(
    sidebarMenu(
      menuItem("plot", tabName = "plot"),
      menuItem("slider", tabName = "slider")
    )
  ),
  dashboardBody(
    tabItems(
      # First tab content
      tabItem(
        tabName = "plot",
        fluidRow(
          box(plotOutput("plot1", height = 250)),
        ),
        fluidRow(verbatimTextOutput('longtext')),
        fluidRow(
          box(
            title = "slider",
            sliderInput("slider", "Number of observations:", 1, 100, 50)
          )
        )
      )
    )
  )
)

server <- function(input, output) {
  output$plot1 <- renderPlot({hist(rnorm(500)[seq_len(input$slider)])})
  
  output$longtext <- renderText({paste0(rep('blah', 100), collapse = '\n')})
}

shinyApp(ui, server)

但它的行为更像是在启用目录的情况下运行 R 降价。与下面的代码类似,单击目录中的部分会转到主应用程序中的相关部分。

---
title: "Untitled"
output:
  html_document:
    toc: true
    toc_float: true
---

### section 1

`r paste0(rep('blah', 100), collapse = '<br/>')`

### section 2

section content

【问题讨论】:

    标签: r shiny r-markdown


    【解决方案1】:

    一种可能的解决方案是使用闪亮的文档。

    ---
    title: "Untitled"
    runtime: shiny
    output: 
      html_document:
        toc: true
        toc_float: true
    ---
    
    ### section 1
    ```{r, echo=FALSE}
    sliderInput("slider", "Number of observations:", 1, 100, 50)
    
    renderText({paste0(rep('blah', 100), collapse = '\n')})
    ```
    
    ### section 2
    ```{r, echo=FALSE}
    renderPlot({hist(rnorm(500)[seq_len(input$slider)])})
    ```
    

    【讨论】:

    • 我认为最好将 Rmarkdown 与 runtime: shiny 一起使用,或者使用 Shinydashboard 包,而不是同时使用。 Rmarkdown 感觉更像是一个动态文档,而 shinydashboard 更像是一个 web 应用程序,两者都很棒,我建议从 Rmarkdown 和闪亮开始,然后转到仪表板,看看什么效果最好
    • @DanielJachetta 我在上面使用shinydashboard 的唯一原因是为了展示我的想法。也许这不是必需的,R markdown 示例就足够了。
    猜你喜欢
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    • 2012-08-10
    • 2020-09-22
    • 1970-01-01
    • 1970-01-01
    • 2017-12-26
    • 1970-01-01
    相关资源
    最近更新 更多