Attach ggplot image to tweet through Twitter share widget in Shiny app

I have a Shiny app that includes a widget to share a tweet with some pre-loaded text. It appears on the app as a button that says "Tweet" that sends the text located in the data-text line of the tags$div section of the code. I'd like to be able to also include an image of the ggplot chart in the tweet that's created when people use the Shiny app online.

Is this even possible? Below is my minimal reprex.

ui:

ui <- fluidPage(
    mainPanel(
      plotOutput("draftPlot"),
      tags$div(
        HTML("<div style='float:right'>
             <a href='https://twitter.com/share' 
             class='twitter-share-button' 
             align='middle' 
             data-url='www.mywebsite.com' 
             data-text='Insert text here!' 
             data-size='large'>Tweet
             </a>
             <script>!function(d,s,id){
             var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';
             if(!d.getElementById(id)){
             js=d.createElement(s);
             js.id=id;
             js.src=p+'://platform.twitter.com/widgets.js';
             fjs.parentNode.insertBefore(js,fjs);
             }
             }(document, 'script', 'twitter-wjs');
             </script>
             </div>")
        ))
)

server:

server <- function(input, output) {
  
 
  output$draftPlot <- renderPlot({    
    ggplot() +
      geom_smooth() +
      geom_point() 
  })

  
}

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.