I am trying to get two text fields to display based on a reactive user defined ID. However, what I have currently is not displaying any text for the desired fields. I thought it had to do with the fact that there are 25 data points with the same ID_no (I am using the data to plot, but since it was unrelated to my question, I removed the plot). However, after removing the data in troubleshooting, no text was being displayed still. I am pretty sure my error is in lines 51 and 52 of the code, but I am unsure how to correct it. Any help with troubleshooting is appreciated.
#Check packages to use in library
{
library('shiny') #allows for the shiny app to be used
library('magrittr')
}
#Data
ID_no <- 123
Data_val <- sample(0:100, 25)
employee_name <- as.character("Employee1")
date <- Sys.Date()
ID_1 <-data.frame(ID_no, Data_val, employee_name, date)
ID_no <- 456
Data_val <- sample(0:100, 25)
employee_name <- as.character("Employee2")
date <- Sys.Date()-10
ID_2 <-data.frame(ID_no, Data_val, employee_name, date)
data <-rbind(ID_1, ID_2)
IDchoices <- as.character(unique(data$ID_no))
# UI
ui <- fluidPage(
fluidRow(
column(4,
wellPanel(
selectInput(inputId = "ID", label="Select ID:", choices = IDchoices, selected = "1", multiple = FALSE, selectize = TRUE)
),
wellPanel(span(h5(strong("Employee:")), h5(textOutput("Staff_name"))),
span(h5(strong("Date:")),h5(textOutput("Date"))))
)
)
)
#SERVER
server <- function(input, output, session)
{
filteredData <- reactive({
m <- data %>% filter(
ID_no %in% input$ID
)
m
})
output$Staff_name <- renderText({ filteredData()$employee_name })
output$Date <- renderText({ filteredData()$date })
}
#Run the Shiny App to Display Webpage
shinyApp(ui=ui, server=server)
stats::filterordplyr::filterin the reactive part on the server side? If you're usingstats::filteryou get an object of the classmtsand then subsetting with ...()$Date won't work. If you're usingdplyr::filterto get the subset, you should changerenderText({ filteredData()$Date })to renderText({ filteredData()$date }). - Michal MajkaDatebutdate- Michal Majkadplyrpackage or write explicitlydplyr::filter. If you don't do this then shiny will usestats::filterfunction.dplyrwill automatically import pipes frommagrittrpackage. - Michal Majka