为RShiny仪表板使用流体页面和列布局

问题描述 投票:0回答:1

我想使用下面的代码来输出一个仪表板,该仪表板的左侧为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个回答
0
投票

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

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")
    )
  )
)

作为您的用户界面?

**编辑**

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

enter image description here

其图位于主面板的顶部右侧,而面板中的两个控件位于左侧:顶部的输入文件和下方的操作按钮。这似乎符合您的要求。 (尽管我不确定您所说的“动作图”是什么意思,所以我假设您的意思是“动作按钮”,因为这就是您的示例代码所具有的意思。)请注意,该图实际上并未出现,因为我尚未安装pheatmap软件包,您还没有提供任何测试数据。

© www.soinside.com 2019 - 2024. All rights reserved.