For each input from the user, I would to render a different video based on a different src:
library(shiny)
Targeted_sector<- c('Wastewater Treatment','Agriculture Schemes','Dams' )
Targeted_year<- c('2021','2022','2023' )
Wastewater_Treatment<- read.csv("data/Wastewater_Treatment.csv", header=TRUE,
check.names=FALSE)
Agriculture_Schemes<- read.csv("data/Agriculture_Schemes.csv", header=TRUE,
check.names=FALSE)
Dams<- read.csv("data/Dams.csv", header=TRUE, check.names=FALSE)
ui <-
fluidPage(
sidebarPanel(
selectInput('sector',
'Targeted Sector:',
Targeted_sector),
selectInput('year1',
'Targeted Year:',
Targeted_year)
)
)
mainPanel(
tags$iframe(width="560", height="315", src=uiOutput('link1'), frameborder="0",
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture",
allowfullscreen=NA)
# here I want src to change dynamically according to the input$sector
)
server <- function(input, output) {
SelectSector <-reactive({
if (input$sector == 'Wastewater Treatment')
{
return(Wastewater_Treatment)
}
else if (input$sector == 'Agriculture Schemes')
{
return(Agriculture_Schemes)
}
else
{
return(Dams)
}
})
SelectYear <- reactive({
if (input$year1 %in% SelectSector()$years)
{
SelectSector() %>%
filter(years == input$year1) %>%
pull(link) # This contain the targeted link for example "https://www.youtube.com/watchv=L7KSftmYce0" but it did not work
}
})
output$link1 <-
renderUI({
tagList(SelectYear())
})
}
shinyApp(ui = ui, server = server)