Reputation: 11
I'm very new to Shiny and R, and I'm having an issue. I'm writing an app that reads a csv file containing a list of athlete names and all their collected information, i.e speed, height, weight, etc..
I'm trying to allow for updating that information. So I created a vector containing 5 column values from the rows for a selected athlete. This information is their name, class year, sport, coach and entry date. I've got the checkBoxGroupInput working. The problem is once I have that returned value from the check box I can't split apart the information to be able to select that specific row from the dataframe for updating.
So here's some of the important code:
ui <- fluid panel
#other code is here that is working. Just focusing on this code for this issue
tabPanel(title = "Update Info", value = "updateAth",
tags$h3("Update Athlete's Information"),
sidebarLayout(
sidebarPanel(
selectizeInput("updtAth","Choose Ahtlete",choices = unique(athletes$ATHLETE),options = list(placeholder = '', onInitialize = I('function() {this.setValue("");}'))),
br(),
#action button to select the patient
actionButton("selectAth","Select"),
br(),
uiOutput("nextSteps")
), #end sidebarPanel
mainPanel(
uiOutput("moreSteps"),
) #end main panel
)
)
)
server <- function(input,output,session) {
observeEvent(input$selectAth, {
athDF <- data.frame(subset.data.frame(athletes,athletes$ATHLETE == input$updtAth, select = c("CLASSMAN","SPORT","COACH","DATE")))
rws <- nrow(athDF)
values <- vector(length = rws)
#create the list of choices in a for loop
for (i in 1:rws) {
values[i] <- paste(input$updtAth,athDF[i,1],athDF[i,2],athDF[i,3],athDF[i,4])
} # end for loop
output$nextSteps <- renderUI({
tagList(
br(),
checkboxGroupInput("row","Choose the row to update",choices = as.list(values)),
br(),
actionButton("updateRow","Update Row")
) #end tagList
}) # end output renderUI
################ this is the first thing I tried and I get this as my output -- "this is it NA Harry, Barry"
rowToString <- renderText(input$row)
updtclass <- rowToString()[2] #this value should be 3
#####################When I try this I get this as my output --- "this is it Dolphin, Barry "
updtclass <- input$row[2] #this value should be 4
output$text <- renderText({paste("this is the it", updtclass," ",input$updtAth)})
observeEvent(input$updateRow, {
output$moreSteps <- renderUI({
fluidRow (
#dataTableOutput('getTable'),
textOutput('text'),
br(),
tags$h3("Only fill in the attributes that need to be changed"),
column(3,
textInput("upDtht","Height",value = NULL,width = '100px', placeholder = "in inches"),
textInput("upDtwt","Weight", value = NULL, width = '100px'),
textInput("upDtsport","Sport", value = NULL, width = '100px'),
textInput("upDtspeed","Speed", value = NULL, width = '100px'),
textInput("upDtagility","Agility", value = NULL, width = '100px')
), #end column
column(
4,offset = -1,
textInput("upDtcmj","CMJ",value = NULL, width = '100px'),
textInput("upDtsj","SJ",value = NULL, width = '100px'),
textInput("upDtnotes","Notes", value = NULL, width = '800px'),
textInput("upDtdate","Date", value = format(Sys.Date(),format="%m/%d/%Y"), width = '100px'),
br(),
actionButton("update","Update")
), #end next column
) #end fluid row
}) # end renderUI moreSteps
}) #end observe Event updateRow
observeEvent(input$update, {
#i'll work this out later
) #end observe Event update
} #end work inside first observeEvent
) #end observeEvent update info
}
I just can't figure out how to pull each value from the check box. An Example of what the data in the checkbox will return is:
"Harry, Barry" "3" "Basketball" "Coach Jones" "07/15/2019"
My goal is to pull each individual value and put it in a variable to use to pull that specific row out of the dataframe so I can get the end user to update it. athlete = Harry, Barry, classyear = 3, sport = Basketball, coach = Coach Jones, updtDate = 07/15/2019
I hope this makes sense.
Upvotes: 1
Views: 812
Reputation: 1513
input$checkBoxGroupInput[1]
will give you the first, input$checkBoxGroupInput[2]
the second and so on. In summary the output of a checkBoxGroupInput
is a vector.
Here is a minimal example:
library(shiny)
ui <- fluidPage(
checkboxGroupInput("checkboxGroupInput","checkboxGroupInput", choices = c(1, 2, 3))
)
server <- function(input, output, session) {
#Runs when checkboxGroupInput is changed
observeEvent(input$checkboxGroupInput, {
#Clear console
cat("\014")
#Print the selection(s) of checkboxGroupInput to the console
print(paste('1st value:', input$checkboxGroupInput[1]))
print(paste('2nd value:', input$checkboxGroupInput[2]))
print(paste('3rd value:', input$checkboxGroupInput[3]))
})
}
shinyApp(ui, server)
I can't run your code, but it sounds like a checkBoxGroupInput
might not be the right input in this case. Perhaps a series of drop down boxes would be more useful.
Upvotes: 1