How would I hide the action button until all selections are made?
r, shiny
Solution
You can add the `actionButton` to your `renderUI`. I also tidied up your `server.R` as everything was wrapped in an `observe` which would probably not be best going forward.
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])
}
})
}
)
)
Problem
I was wondering if there was a way to hide the action button on my shiny app until after the variable selections are displayed in the side panel. I have been having trouble achieving this with a uiOutput for the button as it confuses the dataTable, as it thinks that input$submit is an empty value. Here is the code so far: 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') ) )) ``` 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]) })} }) }) ``` tl;dr I want to prevent a user from pushing the "Submit" button before they select a file to upload. This is proving to be difficult for me. Thanks in advance for all of your help! :)