My goal with this shiny application is for people to be able to interactively match correct spellings of words to existing words. This is what I came up with so far which works and runs but it throws an error also. My question is, is there a better way to have the dropdown menu's formatted, how can I fix this error and also how can I then have the dataframe/table with users input saved after the fact.
Thanks!
The error:
Warning: Error in data.frame: arguments imply differing number of rows: 5, 0
101: stop
100: data.frame
99: renderDataTable [#13]
98: func
85: renderFunc
84: output$table
3: runApp
2: print.shiny.appobj
1: <Anonymous>
The Code:
# Load Libraries
library(shiny)
words <- c("aapple", "apple", "bnanana", "pear", "banana")
choices = c("", "apple", "banana", "pear")
# Create User Interface
ui <- fluidPage(
titlePanel("Matching Words with Dropdown Menus"),
sidebarLayout(
sidebarPanel(
uiOutput("words_list"),
hr(),
uiOutput("dropdown_list")
),
mainPanel(
h4("Results"),
hr(),
dataTableOutput("table")
)
)
)
# Create Server Function
server <- function(input, output) {
# Output List of Dropdown Menus
output$dropdown_list <- renderUI({
lapply(words, function(x){
selectInput(paste0("select_", x), x,
choices = choices)
})
})
# Output Table of Results
output$table <- renderDataTable({
data.frame(word = words,
type = sapply(words, function(x){
input[[paste0("select_", x)]]
}))
})
}
# Create Shiny App
shinyApp(ui = ui, server = server)