【问题标题】:Shiny dashboard body is displayed like it includes rmd output in all tabs after creating rmd output in one tab在一个选项卡中创建 rmd 输出后,闪亮的仪表板主体显示为在所有选项卡中包含 rmd 输出
【发布时间】:2021-03-07 20:00:26
【问题描述】:

我有一个带有 3 个 tabItems 的闪亮仪表板。在名为Results 的第三个文件中显示了一个rmd 文件。问题是,只要我打开此选项卡并显示 rmd 报告,其他选项卡中的正文就会发生变化,并且会像那里生成报告一样显示。为什么会这样?

rmd 文件

---
title: "An example Knitr/R Markdown document"
output: html_document
---


{r chunk_name, include=FALSE}
x <- rnorm(100)
y <- 2*x + rnorm(100)
cor(x, y)

和 app.r 文件

library(shiny)
library(shinydashboard)
library(shinydashboardPlus)
library(shinyjs)
library(knitr)
mytitle <- paste0("Life, Death & Statins")
dbHeader <- dashboardHeaderPlus(
  titleWidth = "0px",
  tags$li(a(
    div(style = "margin-left:-15px;margin-bottom:-83px;margin-top:-15px;padding: 0px 1190px 0px 0px ; width: 290px;",
        img(src = 'download.png', height = "125px",width="232px")),
    div(style="display: inline;margin-top:-35px; padding: 0px 90px 0px 1250px ;font-size: 58px ;color: black;font-family:Times-New Roman;font-weight: bold; width: 500px;",HTML(mytitle)),
    div(style="display: inline;margin-top:25px; padding: 0px 0px 0px 1250px;vertical-align:top; width: 150px;", actionButton("well", "Welcome")),
    div(style="display: inline;padding: 0px 0px 0px 0px;vertical-align:top; width: 150px;", actionButton("conse", "Consent")),
    div(style="display: inline;padding: 0px 0px 0px 0px;vertical-align:top; width: 150px;", actionButton("res", "Results"))
    
  ),
  class = "dropdown")
  
  
)

shinyApp(
  ui = dashboardPagePlus(
    header = dbHeader,
    sidebar = dashboardSidebar(width = "0px",
                               sidebarMenu(id = "sidebar", # id important for updateTabItems
                                           menuItem("Welcome", tabName = "well", icon = icon("house")),
                                           menuItem("Consent", tabName = "conse", icon = icon("line-chart")),
                                           menuItem("Results", tabName = "res", icon = icon("line-chart"))
                               )           ),
    body = dashboardBody(
      
      useShinyjs(),
      tags$script(HTML("$('body').addClass('fixed');")),
      
      tags$head(tags$style(".skin-blue .main-header .logo { padding: 0px;}")),
      tabItems(
        tabItem("well",
                fluidRow(
                  column(5,),
                  column(6,
                         actionButton("button", "Get started",style='padding:4px; font-size:140%')))),
        tabItem("conse",
                fluidRow(column(3,h3("Concent"))),
                fluidRow(column(3,h5(strong("Purpose of the research")))),
                fluidRow(column(12,"Your practice is being invited to participate in a study which aims to explore the relationship of statin prescriptions and all cause mortality in elderly general practice patients")),
                

        ),
        tabItem("res",
                tags$hr(),
                fluidRow(
                  column(3,actionButton('spdf', "Save PDF",style='padding:4px; font-size:180%')
                  ),
                  column(6,
                         uiOutput('markdown'))))
      ),
      
      
      
    )
    
  ),
  server<-shinyServer(function(input, output,session) { 
    hide(selector = "body > div > header > nav > a")
    output$markdown <- renderUI({
      HTML(markdown::markdownToHTML(knit('ex.rmd', quiet = TRUE)))
    })
    observeEvent(input$well, {
      updateTabItems(session, "sidebar", "well")
    })
    
    observeEvent(input$conse, {
      updateTabItems(session, "sidebar", "conse")
    })
    
    observeEvent(input$res, {
      updateTabItems(session, "sidebar", "res")
    })
    
    
  }
  )
)

【问题讨论】:

    标签: r shiny markdown knitr


    【解决方案1】:

    rmd 代码添加属性

    max-width: 800px;

    要删除它,您可以使用 fragment.only 选项

    HTML(markdown::markdownToHTML(knit('exx.rmd', quiet = TRUE), fragment.only=TRUE))
    

    或者,您可以将以下内容添加到您的ui

    tags$head(tags$style(HTML("
                                   body {
                                      width: 100% !important;
                                      max-width: 100% !important;
                                   }
    
                                   ")))
    

    那么对前面的标签就没有影响了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 2020-12-17
      • 1970-01-01
      • 2021-12-14
      • 1970-01-01
      相关资源
      最近更新 更多