为 RShiny 仪表板使用流体页面和列布局
Using fluidpage and column layout for RShiny dashboard
我想使用下面的代码输出一个仪表板,左侧有 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 fluidpage 和列,可以提供帮助吗?
我不完全确定你想要什么,但你的 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")
)
)
)
作为你的 UI?
** 编辑 **
如果根据您在下方的评论,这不是您想要的,请提供更多信息。这是此布局给我的屏幕截图:
主面板顶部右侧有您的绘图,左侧面板中有两个控件:顶部的输入文件和下方的操作按钮。这似乎符合您在问题中的规格。 (虽然我不确定 "action plot" 是什么意思,所以我假设你的意思是 "action button" 因为那是你的示例代码。)请注意,情节实际上并没有出现,因为我没有安装了 pheatmap
包,但您没有提供任何测试数据。
我想使用下面的代码输出一个仪表板,左侧有 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 fluidpage 和列,可以提供帮助吗?
我不完全确定你想要什么,但你的 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")
)
)
)
作为你的 UI?
** 编辑 **
如果根据您在下方的评论,这不是您想要的,请提供更多信息。这是此布局给我的屏幕截图:
主面板顶部右侧有您的绘图,左侧面板中有两个控件:顶部的输入文件和下方的操作按钮。这似乎符合您在问题中的规格。 (虽然我不确定 "action plot" 是什么意思,所以我假设你的意思是 "action button" 因为那是你的示例代码。)请注意,情节实际上并没有出现,因为我没有安装了 pheatmap
包,但您没有提供任何测试数据。