将ggplot图像附加到通过Shiny应用程序中的Twitter共享小部件进行鸣叫

问题描述 投票:0回答:1

我有一个Shiny应用,其中包含一个小部件,可与一些预加载的文本共享一条推文。它在应用程序上显示为“ Tweet”按钮,该按钮发送位于代码的tags $ div部分的数据文本行中的文本。我希望还能在人们在线使用Shiny应用程序时创建的推文中包含ggplot图表的图像。

这甚至可能吗?我已经看到建议使用Twitter卡,但我不熟悉这些卡,也不知道如何使用该卡。

以下是我的最低要求。如果您想查看完整格式的应用程序,则该应用程序托管在ffevaluator.com/tools/draftevaluator上。

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 <- function(input, output) {


  output$draftPlot <- renderPlot({    
    ggplot() +
      geom_smooth() +
      geom_point() 
  })


}

我也将此内容发布在RStudio社区网站上(在此处发布:https://community.rstudio.com/t/attach-ggplot-image-to-tweet-through-twitter-share-widget-in-shiny-app/67867),但尚未得到任何回复。

html r twitter shiny
1个回答
0
投票

不幸的是,Twitter网络共享弹出窗口(twitter.com/share)无法包含图像。 Twitter Card could的工作方式是,如果您在Tweet文本中共享指向静态网页的链接,并且该页面具有包含图片的标记,那么该图片将显示为预览链接。对于那是否可以在这里工作,我不熟悉Shiny。

© www.soinside.com 2019 - 2024. All rights reserved.