搜索
查看: 2631|回复: 2

shiny网页里面的图片不是表面看起来那样

[复制链接]

634

主题

1182

帖子

4030

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
4030
发表于 2017-5-8 14:39:30 | 显示全部楼层 |阅读模式
正常的图片一般是:
[AppleScript] 纯文本查看 复制代码
<img class="irc_mi" src="http://compgenomics2014.biology.gatech.edu/images/e/e1/Ucsc.jpg" alt="Image result for ucsc browser clean setting" width="819" height="461" style="margin-top: 82px;">

可以看到,里面的img的src是一个图片,
但是shiny里面的图片,鼠标滑过,或者你单击,它是给浏览器发送信息 了的。
比如下面代码:
[AppleScript] 纯文本查看 复制代码
library(shiny)
# A demonstration of clicking, hovering, and brushing
shinyApp(
  ui = basicPage(
    fluidRow(
      column(width = 4,
             plotOutput("plot", height=300,
                        click = "plot_click",  # Equiv, to click=clickOpts(id="plot_click")
                        hover = hoverOpts(id = "plot_hover", delayType = "throttle"),
                        brush = brushOpts(id = "plot_brush")
             ),
             h4("Clicked points"),
             tableOutput("plot_clickedpoints"),
             h4("Brushed points"),
             tableOutput("plot_brushedpoints")
      ),
      column(width = 4,
             verbatimTextOutput("plot_clickinfo"),
             verbatimTextOutput("plot_hoverinfo")
      ),
      column(width = 4,
             wellPanel(actionButton("newplot", "New plot")),
             verbatimTextOutput("plot_brushinfo")
      )
    )
  ),
  server = function(input, output, session) {
    data <- reactive({
      input$newplot
      # Add a little noise to the cars data so the points move
      cars + rnorm(nrow(cars))
    })
    output$plot <- renderPlot({
      d <- data()
      plot(d$speed, d$dist)
    })
    output$plot_clickinfo <- renderPrint({
      cat("Click:\n")
      str(input$plot_click)
    })
    output$plot_hoverinfo <- renderPrint({
      cat("Hover (throttled):\n")
      str(input$plot_hover)
    })
    output$plot_brushinfo <- renderPrint({
      cat("Brush (debounced):\n")
      str(input$plot_brush)
    })
    output$plot_clickedpoints <- renderTable({
      # For base graphics, we need to specify columns, though for ggplot2,
      # it's usually not necessary.
      res <- nearPoints(data(), input$plot_click, "speed", "dist")
      if (nrow(res) == 0)
        return()
      res
    })
    output$plot_brushedpoints <- renderTable({
      res <- brushedPoints(data(), input$plot_brush, "speed", "dist")
      if (nrow(res) == 0)
        return()
      res
    })
  }
)


你把这个代码在R里面运行就好了,可以看到:

而查看源代码,可以看到这个图片其实是大串字符:


字符如下:
[AppleScript] 纯文本查看 复制代码
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAakAAAEsCAMAAABOj7wCAAAAeFBMVEUAAAAAADoAAGYAOjoAOmYAOpAAZrY6AAA6ADo6AGY6OpA6kNtmAABmADpmAGZmOgBmZjpmtttmtv+QOgCQOjqQOmaQZpCQkDqQtpCQ29uQ2/+2ZgC2/7a2///bkDrb25Db/7bb/9vb////tmb/25D//7b//9v///85bQcgAAAACXBIWXMAAAsSAAALEgHS3X78AAAJc0lEQVR4nO2djZabNhBGcdL1prE3bb3ptjUNSdd/7/+GRYA39howYkZiPvHdk3N8NjZjWdeSBhhwdiIYZFM3gAyEplCgKRRoCgWaQoGmUKApFGgKBZpCgaZQoCkUaAoFmkKBplCgKRRoCgWaQoGmUKApFGgKBZpCgaZQoCkUaAoFmkKBplCgKRRoCgWaQoGmUKApFGgKBZpCgaZQoCkUaAoFmkKBplCgKRRoCgWaQoGmUKApFGgKBZpCgaZQoCkUaAoFmkKBplCgKRRoCgWaQoGmUKApFO6b2j9mjg/fIrSGdHPX1PF5Uz3uHl6DN4b0cNfU4cu3q0cyEZIxlRFVhKZOh3UVpmWdYjaiithUmG3JDTSFgthUmaUvtq0ZBU11cnfVadtG9HSdURyfVzTlQ3Ya0TtSU7WhfHlhamCyMmMmMdVk6cXHXzmmBjOJqTJLX7mH4jZNp6lOplinAm1LbqApFGgKBZpCQZylr5uUnBlFYMRjyu32jt2WeCCf/Q5P29HbkuFwnUKBplCgKRRoCgWaQoGmUKApFGgKBZpCgaZQoCkUaAoFmkKBplCgKRRoCgWaQiGAKVY7B4FjCgWaQoGmUKApFGgKBZpCgaYmxGtPhqbC0ifD79JEmgp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plCgKRRoCgWaQoGmUKApFGgKBZpCgaZQSMuUKyXfDSpaPd9gEofkTO0//fPy4/b3vFteGaNBiiRk6rDOfvlts//834sr/dpVF8McvvxVFXGVz334dvlQvnLq9nqSkKl8VerZHNZ/OFOuALZYlk4eXnelnLwusvz5sNMp649IOqacm2pOy7NsdS4oP6w3roDf/VU+f344vxKKdExVtbOuAvz48qP0s390014lLN9U18Ysts3D2yuhSMdUM1J2y+PLa15dZbF7eHWm3JiqU4yLB46pCWnWqacy93vausp9Z2q9rIr489X7B65T03F8rjK65krovM79nn4/534XD80rsUjI1Jnjy88LNGRXf5oiQVOX0BSJDk2hQFMo0BQKNIUCTaFAUyjQFAo0hQJNoUBTKNAUCjSFAk2hQFMo0BQK/wMGjoKdnrZMzAAAAABJRU5ErkJggg==" width="425" height="300" style="-webkit-user-drag: none;">

这样做的好处是别人无法爬虫下载你的图片了,你也不需要上传图床了,反正图片都被你字符化了。
O(∩_∩)O哈哈哈~

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
你这个问题很复杂,需要打赏,请点击 http://www.bio-info-trainee.com/donate 进行打赏,谢谢
回复

使用道具 举报

5

主题

22

帖子

172

积分

注册会员

Rank: 2

积分
172
发表于 2017-5-9 13:14:20 | 显示全部楼层

这是base64编码的图片,复制这个字符串到浏览器地址栏就可以看啦(而且还可以右键另存为)爬虫也可以针对开头是data:image/png;base64的数据开始爬,然后转一个格式也能存下来的

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 支持 反对

使用道具 举报

4

主题

51

帖子

327

积分

中级会员

Rank: 3Rank: 3

积分
327
发表于 2017-8-8 14:07:58 | 显示全部楼层
base64的字符串拿到了后可以转个格式,在线有很多,而且python等语言也自带这样的函数。稍微提高了爬的门槛
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|小黑屋|生信技能树 ( 粤ICP备15016384号  

GMT+8, 2019-8-19 08:26 , Processed in 0.034436 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.