2017-05-17 16 views
0

私はかなり光沢があります。 私はアプリケーションで作業しています。ある時点で、csvファイルをアップロードするか、テキスト入力を使用して 'csv'(実際には内部でdata.table)を生成するオプションが提供されています。選択に応じてサイドバーパネルを拡張してアップロードウィジェット(またはメインパネルに表示するテキスト入力)をロードしたいと思っていますShiny:入力タイプの選択後にアップロードウィジェットを追加します。

現在、アップロードウィジェットがアプリケーションのロード時に表示されます。 私は助けていただきありがとうございます!

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) 

答えて

1

conditionalPanel()を使用することができるが、私はこれらの条件を指定 に容易になり、この場合だと思うrenderUI():複数渡す場合

(ドントがtagList()を使用することを忘れUIエレメントはrenderUI()

output$templ_upload <- renderUI({ 
    if(input$radio == 1){ 
     tagList(
     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')) 
    ) 
    } 
    }) 

    output$templ_create <- renderUI({ 
    if(input$radio == 2){ 
     textInput("table", "Table", "Sample text") 
    } 
    }) 
+0

ここで、conditionalPanel()はより適切でしょうか?条件付き出力を含むより複雑な例については – Rivka

+1

ですが、主に私が言っていることは... – BigDataScientist

関連する問題