I am building a simple shiny UI that accepts input and appends them as a row to one of two tables based on a "TYPE". However, I am getting the following error.
"Error in restoreInput(id = inputId, default = value): argument "value" is missing, with no default"
I am very new to shiny and am struggling to understand which input may be throwing the error and where I should add "restoreInput()" to fix it. My script is as follows...
library(shiny)
ui <- fluidPage(
titlePanel("Maintenance/Supply Request:"),
sidebarLayout(
sidebarPanel("Ticket",
selectInput(inputId = "Type", label = "Type", c("Maintenance","Supply")),
textInput(inputId = "Name", label = "Name",value = " "),
textInput(inputId = "Department", label = "Department", value = " "),
dateInput(inputId = "Date", label = "Date", format = "dd-mm-yyyy"),
numericInput(inputId = "Urgency", label = "Urgency", min = 1, max = 5),
textInput(inputId = "Request", label = "Request", value = " "),
actionButton(inputId = "Submit", label = "Submit Ticket")
),
mainPanel(
tabsetPanel(
tabPanel("Maintenance", tableOutput("Maintenance")),
tabPanel("Supply", tableOutput("Supply"))
)
)
)
)
server <- function(input,output){
if ( (input$Type = "Maintenance")){
Maintenance <- reactiveValues()
Maintenance$df <- data.frame(Name = character(),
Department = character(),
Date = character(),
Urgency = integer(),
Request = character())
observeEvent(input$Submit, {
new_row <- data.frame(Name = input$Name,
Department = input$Department,
Date = input$Date,
Urgency = input$Urgency,
Request = input$Request)
Maintenance$df <- rbind(Maintenance$df, new_row)
})
output$table <- renderTable(Maintenance$df)
} else {
Supply <- reactiveValues()
Supply$df <- data.frame(Name = character(),
Department = character(),
Date = character(),
Urgency = integer(),
Request = character())
observeEvent(input$Submit, {
new_row <- data.frame(Name = input$Name,
Department = input$Department,
Date = input$Date,
Urgency = input$Urgency,
Request = input$Request)
Supply$df <- rbind(Supply$df, new_row)
})
output$table <- renderTable(Supply$df)
}
}
shinyApp(ui = ui, server = server)
Any help would be greatly appreciated.
CodePudding user response:
The issue which gives rise to the error is the missing value
for the numericInput
. However, even after fixing that your app will not work as doing if ( (input$Type = "Maintenance"))
(where of course =
should be ==
) will not work as you are trying to access the value of an input outside of a reactive context.
Overall you could simplify your app and make it work like so:
library(shiny)
ui <- fluidPage(
titlePanel("Maintenance/Supply Request:"),
sidebarLayout(
sidebarPanel(
"Ticket",
selectInput(inputId = "Type", label = "Type", choices = c("Maintenance", "Supply")),
textInput(inputId = "Name", label = "Name", value = " "),
textInput(inputId = "Department", label = "Department", value = " "),
dateInput(inputId = "Date", label = "Date", format = "dd-mm-yyyy"),
numericInput(inputId = "Urgency", value = 1, label = "Urgency", min = 1, max = 5),
textInput(inputId = "Request", label = "Request", value = " "),
actionButton(inputId = "Submit", label = "Submit Ticket")
),
mainPanel(
tabsetPanel(
tabPanel("Maintenance", tableOutput("Maintenance_table")),
tabPanel("Supply", tableOutput("Supply_table"))
)
)
)
)
server <- function(input, output) {
dat <- reactiveValues()
dat$Maintenance <- dat$Supply <- data.frame(
Name = character(),
Department = character(),
Date = character(),
Urgency = integer(),
Request = character()
)
observeEvent(input$Submit, {
new_row <- data.frame(
Name = input$Name,
Department = input$Department,
Date = input$Date,
Urgency = input$Urgency,
Request = input$Request
)
if (input$Type == "Maintenance") {
dat$Maintenance <- rbind(dat$Maintenance, new_row)
} else {
dat$Supply <- rbind(dat$Supply, new_row)
}
})
output$Maintenance_table <- renderTable(dat$Maintenance)
output$Supply_table <- renderTable(dat$Supply)
}
shinyApp(ui = ui, server = server)
#>
#> Listening on http://127.0.0.1:8759