I have dataframe that includes Facebook post URLs and dates. I would like to set up a dashboard that allows the user to filter which Facebook posts are rendered by date. In order to render Facebook posts in Shiny, Javascript code is provided by Facebook and embedded using the following script:
tags$head(HTML(
'<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v6.0&appId=[app_id_here]&autoLogAppEvents=1"></script>'
)
This works for rendering in the UI, but when I use uiOutput()
and renderUI
to render the posts in the Server, the Javascript does not attach to the posts, and nothing is rendered. It's necessary for the posts to render in the server so that the user can filter the posts.
Reprex (but my Facebook app ID is omitted):
library(shiny)
ui <- fluidPage(
tags$head(HTML(
'<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v6.0&appId=[app_id_here]&autoLogAppEvents=1"></script>'
),
#This renders a post
HTML(
'<div class="fb-post" data-href=https://www.facebook.com/facebook/videos/2589424624712161/></div>')
),
#This does not render a post
uiOutput('render_post')
)
server <- function(input, output) {
output$render_post <- renderUI(
HTML('<div class="fb-post" data-href=https://www.facebook.com/facebook/videos/2589424624712161/></div>')
)
}
shinyApp(ui = ui, server = server)