闪亮的R缩小图输出

闪亮的R缩小图输出

本文介绍了闪亮的R缩小图输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Shiny R缩小plotOutput.

我有这个情节:

来自此代码:

#In ui:
fluidRow(
        column(width = 12,
           h4("Diagrama Persistencia"),
           plotOutput("Diagrama")
        )
      )

#In server
output$Diagrama <- renderPlot({
        F_PlotDiag(Diag = isolate(values$data), tipoPlot = input$radioPlot, tamEjeNom = input$sliderTamEjeNom)
      }, height = input$sliderHeight, width = input$sliderWidth)

注意高度和宽度参数.之所以可行,是因为一切都在一个observeEvent上下文中.

如您所见,孔图不会显示在屏幕上.减小高度和宽度的问题是,它看起来像这样:

但是实际上,如果我右键单击并保存第一张图像,它看起来就好于第二张图像:

是否可以通过缩小比例在浏览器中显示整个图?这样就可以像下载图片一样看到它.

我真的对CSS不太了解,因此我无法提供任何逻辑上的尝试,但这是我为HTML尝试的方法:

tags$style(type="text/css", ".shiny-bound-output { transform: 'scale(.5)' }")
  tags$style(type="text/css", ".shiny-plot-output { transform: 'scale(.5)' }")
  tags$style(type="text/css", "#Diagrama { height: 20px }")

没有成功.

解决方案

由于您没有提供可复制的示例,因此请查看此示例是否对您有所帮助.基于 https://stackoverflow.com/a/8839678/4190526

关键是下面一行,它在div下找到ID为distPlot(即ui.R中的图名称)的图像,并使用max-height定义CSS,否则为auto. /p>

tags$style(HTML("div#distPlot img {width: auto; height: auto; max-width: auto; max-height: 400px;}")),

完整代码

library(shiny)

ui <- shinyUI(fluidPage(

   tags$style(HTML("div#distPlot img {width: auto; height: auto; max-width: auto; max-height: 400px;}")),
   titlePanel("Old Faithful Geyser Data"),
   sidebarLayout(
      sidebarPanel(
         sliderInput("bins",
                     "Number of bins:",
                     min = 1,
                     max = 50,
                     value = 30)
      ),
      mainPanel(
         plotOutput("distPlot")
      )
   )
))

server <- shinyServer(function(input, output) {

   output$distPlot <- renderPlot({
      x    <- faithful[, 2]
      bins <- seq(min(x), max(x), length.out = input$bins + 1)

      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   }, width=600, height=1200)
})

shinyApp(ui = ui, server = server)

I'm trying to scale down a plotOutput with Shiny R.

I have this plot:

from this code:

#In ui:
fluidRow(
        column(width = 12,
           h4("Diagrama Persistencia"),
           plotOutput("Diagrama")
        )
      )

#In server
output$Diagrama <- renderPlot({
        F_PlotDiag(Diag = isolate(values$data), tipoPlot = input$radioPlot, tamEjeNom = input$sliderTamEjeNom)
      }, height = input$sliderHeight, width = input$sliderWidth)

Notice the height and width params. This works because all is in an observeEvent context.

As you can see, the hole plot won't fit in the screen. The problem with reducing height and width is that it looks like this:

But actually, if I right click and save the FIRST image, it looks fine unlike the second image:

Is there a way to show the whole plot in the browser by scaling it down? So that I can see it as if I downloaded the image.

I really don't know much about CSS so I can't really provide any logical attempts, but this is what I've tried for my HTML:

tags$style(type="text/css", ".shiny-bound-output { transform: 'scale(.5)' }")
  tags$style(type="text/css", ".shiny-plot-output { transform: 'scale(.5)' }")
  tags$style(type="text/css", "#Diagrama { height: 20px }")

With no success.

解决方案

Since you didn't provide a reproducible example, see if this example helps you. Based on https://stackoverflow.com/a/8839678/4190526

The key is the following line, which finds the image under the div with the id distPlot (i.e. the plot name in ui.R), and define the CSS with a max-height but otherwise auto.

tags$style(HTML("div#distPlot img {width: auto; height: auto; max-width: auto; max-height: 400px;}")),

Full code

library(shiny)

ui <- shinyUI(fluidPage(

   tags$style(HTML("div#distPlot img {width: auto; height: auto; max-width: auto; max-height: 400px;}")),
   titlePanel("Old Faithful Geyser Data"),
   sidebarLayout(
      sidebarPanel(
         sliderInput("bins",
                     "Number of bins:",
                     min = 1,
                     max = 50,
                     value = 30)
      ),
      mainPanel(
         plotOutput("distPlot")
      )
   )
))

server <- shinyServer(function(input, output) {

   output$distPlot <- renderPlot({
      x    <- faithful[, 2]
      bins <- seq(min(x), max(x), length.out = input$bins + 1)

      hist(x, breaks = bins, col = 'darkgray', border = 'white')
   }, width=600, height=1200)
})

shinyApp(ui = ui, server = server)

这篇关于闪亮的R缩小图输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 16:29