【发布时间】:2019-03-04 12:42:39
【问题描述】:
我正在构建一个仪表板页面,用户在其中上传文件并单击操作按钮,它应该运行服务器代码并显示输出,还允许将输出下载为文件。下面是显示基本 UI 的代码。
我需要有关服务器功能的帮助,以将服务器功能中命令的输出呈现到导航栏页面中的“表格”输出,其中前 5 行可以显示在 UI 中,并在单击时下载完整的输出文件“下载列表”按钮。我是 rshiny 的新手。任何帮助都会有所帮助。
library(shiny)
library(shinydashboard)
sidebar <- dashboardSidebar(
sidebarMenu(
menuItem("Documentation", tabName = "documentation",selected=FALSE),
menuItem("Dataset", tabName = "dataset", badgeColor = "green"),
menuItem("Result", tabName = "results", badgeColor = "green")
))
body <- dashboardBody(
tabItems(
tabItem(tabName = "documentation",h3("Tool Documentation")),
tabItem(tabName = "dataset",menuItem(icon = NULL, fileInput("PE", "Upload input file:")),
menuSubItem(icon = icon("refresh"),actionButton("Start","Analyze"))),
tabItem(tabName = "results",navbarPage(tabPanel("summary","Summary",icon = icon("list-alt")),
tabPanel("Table",tableOutput("table"),icon = icon("table")),
downloadButton("downList", "Download List")))))
# Put them together into a dashboardPage
ui <- dashboardPage(dashboardHeader(title = "FanDB"),
sidebar,
body)
# Define server logic
server <- function(input, output, session) {
##run this command on input$PE file on the click of actionButton
output$Table <- renderTable({
input$Start
req(input$PE)
a<-read.delim(input$PE,sep="\t",header=T)
b<-a[a[,6]==2,1]
{
return(b)
}
#Show the results from the actionButton in the Table panel in the navbar page and download the results using downloadButton
})
}
shinyApp(ui, server)
或者在actionButton完成时将当前在sidebarMenu中的“结果”菜单(navbarPage)显示到dashboardBody会比较理想。
【问题讨论】:
标签: r shiny shinydashboard