【发布时间】:2017-10-17 01:47:57
【问题描述】:
我对闪亮还是很陌生。 我正在开发一个应用程序,它提供了上传 csv 文件或使用文本输入生成“csv”的选项(它实际上是内部的 data.table)。根据选择,我希望侧边栏面板扩展并加载上传小部件(或显示在主面板中的文本输入)
目前上传小部件会在应用加载时立即显示。 感谢您的帮助!
ui <- shinyUI(fluidPage(
tagList(
navbarPage( id = 'mynavlist', "My App",
tabPanel("Create Boolean Gates",
sidebarPanel(
radioButtons("radio", label = p("Choose one option"),
choices = list("Upload Template" = 1, "Create Template" = 2),
selected = 1),
tags$hr(),
####only when selection is 'Upload Template'
uiOutput("templ_upload"),
tags$hr()
),
mainPanel(
#####only when upload was selected and after uploading the csv file
tableOutput(outputId = 'table'),
####only when selection is 'Create Template'
uiOutput("templ_create")
)
)
))))
server <- shinyServer(function(input, output) {
#### display upload widget if 'upload template' is chosen
output$templ_upload <- renderUI({
fileInput(inputId = 'templ_file', label = 'Choose a Template in csv
format')
tags$hr()
checkboxInput('header', 'Header', TRUE)
radioButtons('sep', 'Separator',
c(Comma=',',Semicolon=';',Tab='\t'))
})
####show the data after upload in mainpanel
output$table <- renderTable({
if (is.null(input$table)){
h5("You have not uploaded a valid file")
}else{
template_csv <- fread(input$table$datapath, header=input$header,
sep=input$sep,quote=input$quote, check.names = FALSE)
return(template_csv)
}
})
####to be finished
# output$templ_create <- renderUI({
# })
})
shinyApp(ui = ui, server = server)
【问题讨论】:
标签: r file-upload shiny