0

我试图弄清楚如何在 Shiny 应用程序上更好地可视化 ggiraph 图表。问题是:这些图表在桌面和移动设备上看起来很棒,但在移动设备上它们在下方留下了太多空间。

在桌面上

这是我在手机上看到的:

垂直混乱

这是应用程序的布局:

# 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)
4

1 回答 1

0

这个问题的解决方案是把

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

它工作得很好。

于 2021-12-10T11:09:57.800 回答