我正在尝试使用library(shinydashboard)
实现一个fileInput
,为用户提供上传文件的选项(就像here使用一个基本的闪亮UI所做的那样-请找到下面的示例代码)。
我想把fileInput
放在dashboardSidebar
中,放在一个可扩展的menuItem
中,但是不知道它应该放在shinydashboard结构的哪里。
library(shiny)
ui <- fluidPage(
titlePanel("Uploading Files"),
sidebarLayout(
sidebarPanel(
fileInput("file1", "Choose CSV File",
multiple = TRUE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
tags$hr(),
checkboxInput("header", "Header", TRUE),
radioButtons("sep", "Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ","),
radioButtons("quote", "Quote",
choices = c(None = "",
"Double Quote" = '"',
"Single Quote" = "'"),
selected = '"'),
tags$hr(),
radioButtons("disp", "Display",
choices = c(Head = "head",
All = "all"),
selected = "head")
),
mainPanel(
tableOutput("contents")
)
)
)
server <- function(input, output) {
output$contents <- renderTable({
req(input$file1)
df <- read.csv(input$file1$datapath,
header = input$header,
sep = input$sep,
quote = input$quote)
if(input$disp == "head") {
return(head(df))
}
else {
return(df)
}
})
}
shinyApp(ui, server)
1条答案
按热度按时间rt4zxlrg1#
**编辑:**我稍微清理了一下代码,使childfull和childless
menuItem
的区别更加清楚-参数expandedName
和startExpanded
只能用于childfullmenuItem
,而tabName
和selected
只能用于childlessmenuItem
。初步答复:
当然-这是可能的(此示例的修改版本):