2

仕事で行っているモデリングの結果を確認するための、非常にクールな光沢のあるアプリがあります。私が使用しているデバイスの 1 つは、wellPanel にある ggvis 折れ線グラフです。オンラインで表示するためにアプリを展開したいのですが、通常のサイズの画面 (ラップトップ) でアプリを見ると、ggvis プロットが wellPanel の境界線を超えていることがわかります。私は巨大な画面を持っていて、小さな画面で見ていたら、ggvis チャートのサイズをインタラクティブに変更できることを知っているので、大したことではありませんが、人々にそうするように言いたくありません。ggvis チャートのサイズを変更すると、wellPanel が応答するため、これら 2 つのオブジェクトのサイズの間に何らかのリンクがあるはずです。

ユーザーの画面サイズに関係なく、レンダリングされた ggvis チャートのデフォルト サイズをコンテナのデフォルト サイズに設定する方法はありますか? 私は ggvis が SVG でレンダリングされることを知っているので、それを調査することは有益かもしれません。SVG や Vega を直接操作したことはありません。以下にコード例を示します。これは、shinyapps でホストされているアプリへのリンクです。何かご意見は?

注:私は明らかに人々が一緒に働くためにコードを投稿しました。この光沢のあるアプリを機能させる方法について質問しているのではないことを明確にしたいだけだと思います-それは、スタイルを設定する方法です。もちろん、他の提案も歓迎します。乾杯。

ui.r

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")
        )
      )
     ) 
    )
   )
  )

server.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

Global.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