简体   繁体   English

Ggiraph 图表在 Shiny 上调整太多

[英]Ggiraph chart resizes too much on Shiny

I am trying to figure out how to better visualize ggiraph charts on Shiny apps.我试图弄清楚如何更好地可视化 Shiny 应用程序上的 ggiraph 图表。 Here is the problem: the charts look awesome on desktop and mobile but they leave too much space underneath them when on mobile.问题是:图表在桌面和移动设备上看起来很棒,但在移动设备上它们在下方留下了太多空间。

On desktop在桌面上

Here is what I see on mobile:这是我在手机上看到的:

Vertical mess垂直混乱

This is the layout of the app:这是应用程序的布局:

# Define UI for application
ui <- fixedPage(
  tags$style(HTML("
         body {
        background-color: white;
        color: black;
        font-family: 'Garamond'
      }
      h2 {
        font-family: 'Garamond';
      }
      .shiny-input-container {
        color: #474747;
      }")),
  fluidRow(girafeOutput('ggplot'),
           selectInput(
             inputId = 'Country',
             label = 'Countries and territories',
             choices = c(unique(speed_data$location)),
             multiple = FALSE,
             selected = 'Europe'
             
           )),
  fluidRow(style='height:40vh')
)

# Define server logic required to draw a histogram
server <- function(input, output,session) {
  
  dat = reactive({
    speed_data %>% 
      filter(location == input$Country)
  })
  
  map = reactive({
    subset(world, !(is.na(world$value)))
  })
  
  
  output$ggplot <- renderGirafe({gg = ggplot(dat(), aes(
    x = date, y = value)) + 
    geom_line_interactive(aes(group = location, y = value, tooltip = location, color = location)) +
    scale_y_continuous(labels = scales::comma) +
    scale_color_brewer(palette = 'Set1') + 
    picci + theme(legend.title = element_blank(),
                  axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),
                  legend.position = 'none') +
    labs(title = paste("Pandemic's speed |", c(dat()$location)),
         subtitle = 'Daily new cases difference (rolling average, 20 days)',
         caption = 'SOURCE: Our world in data',
         x = '',
         y = '')
  ggiraph(code = print(gg),
          options =  list(
            opts_hover(css = "stroke:#5eba7d88;cursor:pointer;")))
  })
}
# Run the application 
shinyApp(ui = ui, server = server)

THe solution for this problem is to put这个问题的解决方案是把

girafeOutput('myggiraphplot',height = '75%')

And it works just fine.它工作得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM