Hello Everyone,
I am fairly new to R and would love some assistance and some advice with a Shiny dashboard that allows clients to input attendance data.
I have recently began an RShiny dashboard that is meant to create a Client Inputted Attendance Tracking App. The goal of this app is for the client to enter the RShiny Dashboard and then select individuals who attend the event and the date in question (this way, the client can go back to previous days and add in attendance that was forgotten as an example). The data is then graphed in a Ggplot to visualize how frequently individuals attend events over time.
I have the following example data frames:
'''
Playername <- c("Joe", "Fred", "Greg")
Handedness <- c("L", "R", "L")
Roster <- data.frame(Playername, Handedness)
Playername2 <- c("Joe", "Fred")
Date <- c("2021-10-18", "2021-10-19")
Attendance <- data.frame(Playername2, Date)
'''
Below is a simplified version of the User Interface.
'''
tweaks <-
list(tags$head(tags$style(HTML("
.multicol {
height: 420px;
-webkit-column-count: 2; /* Chrome, Safari, Opera */
-moz-column-count: 2; /* Firefox */
column-count: 2;
-moz-column-fill: auto;
-column-fill: auto;
}
"))
))
controls <-
list(#h3("Attendance"),
tags$div(align = 'left',
class = 'multicol',
checkboxGroupInput(inputId = 'AttendanceInput',
label = "Select Players",
choices = c(Roster$Playername),
inline = FALSE)))
ui <-navbarPage(title= "title",
tabPanel(title = "ATTENDANCE",
fluidPage(tweaks,
fluidRow(column(width = 4,
dateInput("dateinputa", "Select Attendance Data", format = "yyyy/mm/dd"),
(controls),
actionButton("submit","SUBMIT")),
column(3,
h4("Filter Attendance Data", align = "center"),
box(collapsible = FALSE,
width= 12,
dateRangeInput("daterange", "Select Date Range",
start = "2021-01-01",
end = Sys.Date(),
min = "2021-01-01",
max = Sys.Date(),
format = "yyyy/mm/dd",
separator = "-"),
selectInput("Playernameinput", "Select Player", choices = Roster$Playername)
))), # closes column
fluidRow(
column(12,
box(width=12,
plotlyOutput(outputId = "plot", height = "500px") %>% withSpinner(type = 1, color = "#B62B34")),
fluidRow(box(width= 12,
dataTableOutput("AttendanceTable") %>% withSpinner(type = 1, color = "#B62B34"))
)
))
)))
'''
Below is the Server function. The goal with the server is to observe the "submit button" event and 1) Add the inputted data into the attendance data frame, 2) write the data frame csv (so that it can be used in the future to save the attendance data - I think this is a good way to achieve this goal), 3) re-read the csv attendance data frame so that the ggolot can be updated with the new data.
Server:
'''
server <- function(session, input, output) {
v <- reactiveValues()
v$AttendanceDF <- read_csv("Data/Source Data/Attendance.csv",
col_types = cols(Date = col_date(format = "%m/%d/%Y"),
Playername = col_character()))
observeEvent(input$submit,{
req(input$dateinputa,input$AttendanceInput)
tmpDF <- data.frame(Date = input$dateinput,Playername = input$AttendanceInput)
v$AttendanceDF <- rbind(v$AttendanceDF,tmpDF)
write.csv(AttendanceDF, "Data/Source Data/Attendance.csv")
v$AttendanceDF <- read_csv("Data/Source Data/Attendance.csv",
col_types = cols(Date = col_date(format = "%m/%d/%Y"),
Playername = col_character()))
})
output$AttendanceTable <- DT::renderDataTable({
v$AttendanceDF
})
}
'''
Based on the code I have written, I get the following error code: Warning: Error in data.frame: arguments imply differing number of rows: 0, 1
I would be very very appreciative for some help and advice with this situation. thank you so much for your time and knowledge.