在完成所有选择之前,我如何隐藏操作按钮?

sug*_*101 5 r shiny

我想知道是否有办法隐藏我闪亮的应用程序上的操作按钮,直到侧面板中显示变量选择.我一直无法通过按钮的uiOutput来实现这一点,因为它会混淆dataTable,因为它认为输入$ submit是一个空值.这是迄今为止的代码:

ui.R

library(shiny)

shinyUI(pageWithSidebar(
  headerPanel("CSV Viewer"),

  sidebarPanel(
    fileInput('file1', 'CSV File',
              accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv')),


    tags$hr(),

    checkboxInput('header', 'Header', TRUE),

    radioButtons('sep', 'Separator',
                 c(Comma=',',
                   Semicolon=';',
                   Tab='\t'),
                 'Comma'),

    uiOutput('varselect'),

    actionButton('submit', 'Submit')

  ),

  mainPanel(

    dataTableOutput('contents')

  )
))
Run Code Online (Sandbox Code Playgroud)

server.R

library(shiny)

shinyServer(function(input, output, session) {

  observe({
    csvfile <- input$file1

    if (is.null(csvfile))
      {return(NULL)}

    dt <- read.csv(csvfile$datapath, header=input$header, sep=input$sep,   quote=input$quote)

    output$varselect <- renderUI({

      checkboxGroupInput("var", "Variables", choices = names(dt), select = names(dt))

    })

    if (input$submit > 0) {output$contents <- renderDataTable({

       isolate(dt[ ,input$var])

    })} 
  })
})
Run Code Online (Sandbox Code Playgroud)

tl; dr我想阻止用户在选择要上传的文件之前按下"提交"按钮.事实证明这对我来说很难.

在此先感谢您的所有帮助!:)

jdh*_*son 5

你可以添加actionButton到你的renderUI.我也整理了你,server.R因为一切都包裹在一起,observe这可能不是最好的.

library(shiny)

runApp(list(
  ui = pageWithSidebar(
    headerPanel("CSV Viewer"),

    sidebarPanel(
      fileInput('file1', 'CSV File',
                accept=c('text/csv', 'text/comma-separated-values,text/plain', '.csv')),


      tags$hr(),

      checkboxInput('header', 'Header', TRUE),

      radioButtons('sep', 'Separator',
                   c(Comma=',',
                     Semicolon=';',
                     Tab='\t'),
                   'Comma'),

      uiOutput('varselect')
    ),

    mainPanel(

      dataTableOutput('contents')

    )
  )
  ,server = function(input, output, session) {


    csvfile <- reactive({
      csvfile <- input$file1
      if (is.null(csvfile)){return(NULL)}
      dt <- read.csv(csvfile$datapath, header=input$header, sep=input$sep,   quote=input$quote)
      dt
    })

    output$varselect <- renderUI({
      if(is.null(input$file1$datapath)){return()}
      list(
        checkboxGroupInput("var", "Variables", choices = names(csvfile()), select = names(csvfile()))
        , actionButton('submit', 'Submit')
      )
    })

    output$contents <- renderDataTable({
      if(is.null(input$file1$datapath)){return()}
      if(input$submit > 0){
        isolate(csvfile()[ ,input$var])
      }
    })

  } 

)
)
Run Code Online (Sandbox Code Playgroud)