如何使用Shiny R并排显示两个gvis仪表

时间:2014-12-17 16:46:39

标签: r shiny googlevis

我正在研究闪亮的应用,我试图使用gvisGauge显示基线和模型的准确性。

我已经成功地将它们显示在单独的tabpanels中,也显示在同一个tabpanel中,一个在另一个下面。

但是我想并排显示它们,即在同一个标​​签中水平对齐。我怎样才能做到这一点?尝试搜索选项,但无法获得任何选项。

截至目前,我的示例代码如下

ui.R

library(shiny)
library(googleVis)

shinyUI(fluidPage(
  titlePanel('Guage'),
  sidebarLayout(
    sidebarPanel(
      numericInput('n1', 'Enter your Base Accuracy', 40, 0.5, 100),


      numericInput('n2', 'Enter your Model Accuracy', 40, 0.5, 100)
    ),
    mainPanel(
      tabsetPanel(
      tabPanel("Accuracy Guage",htmlOutput("view1"),htmlOutput("view2"))
    )
  )
)))

server.R

library(shiny)
library(googleVis)

shinyServer(function(input, output) {

  output$view1 <- renderGvis({
    df1 <- data.frame(Label = "Base Accuracy", Value = input$n1)
    gvisGauge(df1,
              options=list(min=0, max=100, greenFrom=90,
                           greenTo=100, yellowFrom=75, yellowTo=89.99,
                           redFrom=0, redTo=74.99, width=300, height=300));  

})

output$view2 <- renderGvis({
  df2 <- data.frame(Label = "Model Accuracy", Value = input$n2)
  gvisGauge(df2,
            options=list(min=0, max=100, greenFrom=90,
                         greenTo=100, yellowFrom=75, yellowTo=89.99,
                         redFrom=0, redTo=74.99, width=300, height=300));  

})


})

1 个答案:

答案 0 :(得分:1)

您可以使用列来指定布局,也可以使用div并使用tags$style并使用display:inline-block

rm(list = ls())
library(shiny)
library(googleVis)

ui =(fluidPage(
  titlePanel('Guage'),
  sidebarLayout(
    sidebarPanel(
      numericInput('n1', 'Enter your Base Accuracy', 40, 0.5, 100),


      numericInput('n2', 'Enter your Model Accuracy', 40, 0.5, 100)
    ),
    mainPanel(
      tabsetPanel(
        tabPanel("Accuracy Guage",
                 column(4,htmlOutput("view1")),
                 column(4,htmlOutput("view2"))
      )
    )
  ))))
server = function(input, output) {

  output$view1 <- renderGvis({
    df1 <- data.frame(Label = "Base Accuracy", Value = input$n1)
    gvisGauge(df1,
              options=list(min=0, max=100, greenFrom=90,
                           greenTo=100, yellowFrom=75, yellowTo=89.99,
                           redFrom=0, redTo=74.99, width=300, height=300));  

  })

  output$view2 <- renderGvis({
    df2 <- data.frame(Label = "Model Accuracy", Value = input$n2)
    gvisGauge(df2,
              options=list(min=0, max=100, greenFrom=90,
                           greenTo=100, yellowFrom=75, yellowTo=89.99,
                           redFrom=0, redTo=74.99, width=300, height=300));  

  })
}
runApp(list(ui = ui, server = server))