【问题标题】:Using fluidpage and column layout for RShiny dashboard为 RShiny 仪表板使用流体页面和列布局
【发布时间】:2020-09-10 12:47:34
【问题描述】:

我想使用下面的代码输出一个仪表板,左侧有 2 个面板(顶部面板:输入文件;底部面板:动作图)和右侧的绘图(主页)。目前,代码输出仪表板顶部的两个面板和底部的绘图,这不是我想要的。我是 Rshiny 的新手,需要帮助。

代码:

library(shiny)
library(pheatmap)

# Define UI for dataset viewer app ----
ui <- fluidPage(

           # App title ----
       titlePanel("plot"),

# Sidebar layout with input and output definitions ----
   sidebarLayout(

# Sidebar panel for inputs ----
   sidebarPanel("Sidebar panel",

  # Input: Selector for choosing dataset ----
  fileInput("file1", "Choose CSV File",
              accept = c(
                "text/csv",
                "text/comma-separated-values,text/plain",
            ".csv")
    ),
    tags$hr(),
    checkboxInput("header", "Header", TRUE)
),

   # tags$hr(),

     sidebarPanel('get heatmap',
              actionButton('getHmap', 'get heatmap'))
),

# Main panel for displaying outputs ----
mainPanel("Plot",
          #column(6, 
             plotOutput("themap"),
             tableOutput("table.output"))
          #)
  )


server = function(input, output, session) {
  a <- reactive({
    inFile <- input$file1
    if (is.null(inFile))
      return(NULL)
tbl <- read.csv(inFile$datapath, header=input$header) #, sep=input$sep,  dec = input$dec)
return(tbl)
  })

  output$table.output <- renderTable({
    a()
  })

  plotdata <- eventReactive(input$getHmap, {
    a <- as.matrix(a()[-1])
    row.names(a) <- a()$ID
    a[is.na(a)] <- 0
    a
   })

 output$themap = renderPlot({ 
    pheatmap(plotdata())
  })
}

shinyApp(ui, server)

有谁知道如何很好地使用 Rshiny 流体页面和列并可以提供帮助?

【问题讨论】:

    标签: r shiny shinydashboard shinyapps shiny-reactivity


    【解决方案1】:

    我不完全确定您想要什么,但您的 UI 中确实有两个 sidebarPanels,这无济于事。怎么样:

    ui <- fluidPage(
      titlePanel("plot"),
      sidebarLayout(
        sidebarPanel("Sidebar panel",
                      # Input: Selector for choosing dataset ----
                      fileInput("file1", "Choose CSV File",
                               accept = c(
                                 "text/csv",
                                 "text/comma-separated-values,text/plain",
                                 ".csv")
                     ),
                     tags$hr(),
                     checkboxInput("header", "Header", TRUE),
                     actionButton('getHmap', 'get heatmap')
        ),
        mainPanel("Plot",
                  #column(6, 
                  plotOutput("themap"),
                  tableOutput("table.output")
        )
      )
    )
    

    作为你的用户界面?

    ** 编辑 **

    如果这不是您想要的,根据您在下面的评论,请提供更多信息。这是这个布局给我的截图:

    您的绘图位于主面板顶部的右侧,左侧面板中有两个控件:顶部的输入文件和下方的操作按钮。这似乎与您在问题中的规格相匹配。 (虽然我不确定你所说的“动作情节”是什么意思,所以我假设你的意思是“动作按钮”,因为这就是你的示例代码所具有的。)请注意,情节实际上并没有出现,因为我还没有安装pheatmap 包,你还没有提供任何测试数据。

    【讨论】:

    • 感谢@Limey,但此修复无法解决问题。
    • 再次感谢@Limey,这正是我想要的。我第一次运行您的修复程序时没有发生什么,但它现在对我有用。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 2015-11-29
    • 1970-01-01
    • 2011-11-18
    相关资源
    最近更新 更多