如何防止slickR删除输入以及如何保持原始大小?

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

我有一个

shiny
应用程序,我正在尝试将一些绘图更新为
slickR.
我得到了一些意想不到的效果:

  1. card_footer
    消失。
  2. 当我折叠
    sidebar
    时,如何保持原始高度和宽度并使其调整大小,就像我只是
    plotOutput
    一样?
  3. 虽然下面有空间,但我得到了绘图的滚动条。
library(shiny)
library(slickR)
library(svglite)
library(tidyverse)
library(gdtools)
library(bslib)
library(shinyWidgets)

ui <-
  page_fluid(layout_sidebar(
    sidebar = tagList(
      pickerInput("select_a", "Select", choices = LETTERS[1:10]),
      pickerInput("select_b", "Select", choices = LETTERS[1:10]),
      pickerInput("select_c", "Select", choices = LETTERS[1:10]),
      pickerInput("select_d", "Select", choices = LETTERS[1:10])
    ) ,
    
    bslib::accordion(open = FALSE, accordion_panel("Ab Panel", actionButton("run", "Run"))),
    
    #plotOutput("plt"), slickROutput("slickr"), card_footer(card_body( layout_column_wrap( width = 1 / 2, actionButton("ab1", "Go1"), actionButton("ab2", "Go2") ) ))
    
  ))

server <-
  function(input, output, session) {
    output$plt <-
      renderPlot({
        ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point()
        
      })
    
    output$slickr <-
      renderSlickR({
        slickR(svglite::xmlSVG({
          methods::show(ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point())
        }, standalone = TRUE))
        
      })
    
  }

shinyApp(ui, server)
r shiny bslib slickr
1个回答
0
投票

输入不会被删除,而是简单地隐藏在默认为 7 x 7 英寸的 svg 下方。假设 DPI 为 96,这超出了

slickROutput
的默认高度 (400px)。

因此,您需要告诉

xmlSVG
使用合适的尺寸并使它们与输出的高度同步:

library(shiny)
library(slickR)
library(svglite)
library(tidyverse)
library(gdtools)
library(bslib)
library(shinyWidgets)

p2i <- function(pixels, dpi = 96) {
  pixels / dpi
}
height <- 400

ui <-
  page_fluid(layout_sidebar(
    sidebar = tagList(
      pickerInput("select_a", "Select", choices = LETTERS[1:10]),
      pickerInput("select_b", "Select", choices = LETTERS[1:10]),
      pickerInput("select_c", "Select", choices = LETTERS[1:10]),
      pickerInput("select_d", "Select", choices = LETTERS[1:10])
    ) ,
    
    bslib::accordion(open = FALSE, accordion_panel("Ab Panel", actionButton("run", "Run"))),

    slickROutput("slickr", height = height), 
    card_footer(
      card_body(
        layout_column_wrap(width = 1 / 2, 
                           actionButton("ab1", "Go1"), 
                           actionButton("ab2", "Go2")
        )
      )
    )
  )
  )



server <-
  function(input, output, session) {
    output$slickr <-
      renderSlickR({
        plt <- svglite::xmlSVG({
          show(
            ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + geom_point()
          )
        }, height = p2i(height), width = p2i(height), standalone = TRUE)
        slickR(
          list(plt, plt)
        )
      })
    
  }

shinyApp(ui, server)

Shinyapp with a slickROutput showing a ggplot and a sidebar and some buttons below

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