2

我有一个非常酷的闪亮应用程序,可以查看我在工作中所做的一些建模的结果。我使用的设备之一是位于 wellPanel 中的 ggvis 折线图。我想部署该应用程序以在线查看,但通过在普通尺寸的屏幕(笔记本电脑)上查看该应用程序,我知道 ggvis 图溢出了 wellPanel 的边界。对我来说没什么大不了的,因为我有一个大屏幕,如果我在一个小屏幕上看它,我知道我可以交互地调整 ggvis 图表的大小,但我不想告诉人们这样做。如果我重新调整 ggvis 图表的大小,wellPanel 会做出响应,因此这两个对象的大小之间必须存在某种联系。

那么有没有办法将渲染的 ggvis 图表的默认大小设置为它所在容器的默认大小,而不管用户的屏幕大小如何?我知道 ggvis 是用 SVG 渲染的,所以探索这可能是富有成效的。我没有直接使用 SVG 或 Vega。示例代码如下,这里是指向Shinyapps 上托管的应用程序的链接。有什么想法吗?

注意:我显然发布了代码供人们使用。我想我只是想明确一点,我不是在问如何让这个闪亮的应用程序运行的问题——更多的是如何设计它。当然,我欢迎其他建议。干杯。

用户界面

library(shiny)
library(ggvis)

shinyUI(navbarPage("Results Viewer", #theme="bootstrap.css",

  tabPanel("Summary Results",
   fluidRow(
      column(2,
       wellPanel(
        uiOutput("regionO"),
        br(),
        uiOutput("scenarioO"),
        br(),
        uiOutput("fuelO"),
        uiOutput("tmpO")
        )
      ),
     column(5,
       wellPanel(style="position: relative;", 
        h5("Employment",align="center"),
        ggvisOutput("plot1")
        )
      ),
     column(5,
      wellPanel(style="position: relative;", 
        h5("Gross Regional Product (Million Dollars)",align="center"),
        ggvisOutput("plot2")
        )
      )
     ) 
    )
   )
  )

服务器.r

librarylibrary(ggvis)
library(dplyr)

shinyServer(function(input, output, session) {

observe({

###### Define Controls ####### 

output$regionO <- renderUI({ checkboxGroupInput(inputId="regionI", label = h4("Regions"), 
        choices = list("Western", "Central", "Southern","Northern", "Capital", "Hudson"),
                   selected="Capital")
}) 

output$scenarioO <- renderUI({ selectInput(inputId="scenarioI", label = h4("Scenario"), 
        choices = list("Low Units, Low Tech"="Lo,Lo" ,"Low Units, High Tech"="Lo,Hi","High Units, Low Tech"="Hi,Lo","High Units, High Tech"="Hi,Hi"),
                   selected="Lo,Lo")
})

output$fuelO <- renderUI({ selectInput(inputId="fuelI", label = h4("Fuel Price"), 
        choices = list("High Price" = "Hi", "Low Price" = "Lo"),
                   selected="Lo")
})

output$tmpO <- renderUI({actionButton("resetI", label = "Reset")}) 

###### Define Data ########### 

if(!is.null(input$resetI)){

chooseRJ <- reactive({ 

     chooseD <- expJ %>% filter(Scenario == input$scenarioI, Region %in% input$regionI, Price == input$fuelI)
     return(chooseD)
 })

sPlot1 <- reactive({

     chooseRJ %>% ggvis(~factor(Period),~Total,stroke=~Region) %>% layer_lines(strokeWidth:=2.5) %>% 
     add_axis("x",title="Analysis Period") %>% add_axis("y",title="Jobs") %>% scale_numeric("y",zero=TRUE) 
}) 

sPlot1 %>% bind_shiny("plot1") 


chooseRV <- reactive({ 

     chooseD <- expV %>% filter(Scenario == input$scenarioI, Region %in% input$regionI, Price == input$fuelI)
     return(chooseD)
})

sPlot2 <- reactive({

        chooseRV %>% ggvis(~factor(Period),~Total,stroke=~Region) %>% layer_lines(strokeWidth:=2.5) %>% 
        add_axis("x",title="Analysis Period") %>% add_axis("y",title="Gross Regional Product $M") %>% scale_numeric("y",zero=TRUE) 
})  

sPlot2 %>% bind_shiny("plot2")  

 } # Test ui controls exist 

}) # End Observeer

}) # End Shiny Server

全球.r

##### Play data ####################

options(stringsAsFactors = FALSE)

expJ <- data.frame(Region=rep(c("Western","Central","Southern","Northern","Capital","Hudson"),times=4,each=8),
                Scenario=rep(c("Lo,Lo","Lo,Hi","Hi,Lo","Hi,Hi"),each=48),
                Price=rep(c("Hi","Lo"),times=24,each=4),
                Period=rep(c(1,2,3,4),times=48),
                Total=rnorm(192,5,1.5))

expV <- data.frame(Region=rep(c("Western","Central","Southern","Northern","Capital","Hudson"),times=4,each=8),
                Scenario=rep(c("Lo,Lo","Lo,Hi","Hi,Lo","Hi,Hi"),each=48),
                Price=rep(c("Hi","Lo"),times=24,each=4),
                Period=rep(c(1,2,3,4),times=48),
                Total=rgamma(192,10,1.78))
4

0 回答 0