For each input from the user, I would like to render a different video based on a different src, I have tested many methods non of them has served my needs, I am relying on extracting the src path from a specific cell in a CSV file
would you please assist me to figure out how to do that, the following line is the main part that is need to be adjusted to solve the problem:
tags$iframe(width="560", height="315", src=uiOutput('link1'))
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)
CodePudding user response:
If the video is on YouTube, you can just use their standard embedded Iframe. Only use the video ID, because you want to use a different URL (