R Shiny应用中的布局,包括R Markdown文件

发布于 2025-02-04 07:55:51 字数 1495 浏览 3 评论 0原文

当我在其中使用R Markdown文件时,我正面临着r shiny的问题,如以下照片所示,我以有线布局大小(仅在屏幕中间,仅在屏幕中间)获得最终结果:

附加到您的代码:

library(shiny)
library(shinydashboard)
library(knitr)

ui <- 
dashboardPage(
  dashboardHeader(title ='Virtual Excursion'), 
  
  dashboardSidebar( sliderTextInput(
    inputId = "mySliderText", 
    label = "Story line", 
    grid = TRUE, 
    force_edges = TRUE,
    choices = c('1','2')
  )
  ),
  dashboardBody(
    fluidRow(
      column(9,  
             box(
               title = "Operations ", 
               closable = FALSE, 
               width = 9,
               status = "primary", 
               solidHeader = FALSE, 
               collapsible = TRUE,
               uiOutput("operations")
             )
      )
    ), 
    fluidRow(
      column(9, 
             box(
               title = "Challenges", 
               closable = FALSE, 
               width = 9,
               status = "primary", 
               solidHeader = FALSE, 
               collapsible = TRUE,
               uiOutput("challenges")
             )
      ) 
    )
  )
)


 server <- function(input, output,session){

 output$operations <- renderUI({
 req(input$mySliderText==1)

 HTML(markdown::markdownToHTML(knit('trial1.rmd', quiet = TRUE)))
 })
}
shinyApp(ui = ui, server = server)

您能指导我如何解决此问题!

I am facing a problem with the layout in R Shiny when I use the R Markdown file inside it I get the final result in a wired layout size (small and only in the middle of the screen ) as shown in the following photo:
enter image description here

Attached to you the code:

library(shiny)
library(shinydashboard)
library(knitr)

ui <- 
dashboardPage(
  dashboardHeader(title ='Virtual Excursion'), 
  
  dashboardSidebar( sliderTextInput(
    inputId = "mySliderText", 
    label = "Story line", 
    grid = TRUE, 
    force_edges = TRUE,
    choices = c('1','2')
  )
  ),
  dashboardBody(
    fluidRow(
      column(9,  
             box(
               title = "Operations ", 
               closable = FALSE, 
               width = 9,
               status = "primary", 
               solidHeader = FALSE, 
               collapsible = TRUE,
               uiOutput("operations")
             )
      )
    ), 
    fluidRow(
      column(9, 
             box(
               title = "Challenges", 
               closable = FALSE, 
               width = 9,
               status = "primary", 
               solidHeader = FALSE, 
               collapsible = TRUE,
               uiOutput("challenges")
             )
      ) 
    )
  )
)


 server <- function(input, output,session){

 output$operations <- renderUI({
 req(input$mySliderText==1)

 HTML(markdown::markdownToHTML(knit('trial1.rmd', quiet = TRUE)))
 })
}
shinyApp(ui = ui, server = server)

Could you please guide me on how to fix this problem!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

野鹿林 2025-02-11 07:55:51

问题在于,您将在HTML页面中包含一个完整的HTML文件。两页之间的冲突导致显示问题。您需要输出一个不包括标题的HTML片段。将fragment.only = true添加到您的Markdown Render函数。

HTML(markdown::markdownToHTML(knit("trial1.rmd", quiet=T),fragment.only = T))

您还可以在RMD文件中的YAML部分中添加输出:html_fragment,以便良好的方法。

The problem is that you are including an full html file within an html page. The conflicts between the two pages is causing the display problem. You need to output an html fragment which excludes the heading. Add fragment.only = TRUE to your markdown render function.

HTML(markdown::markdownToHTML(knit("trial1.rmd", quiet=T),fragment.only = T))

You can also add output: html_fragment in your yaml section inside the rmd file for good measure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文