2

我正在开发闪亮的应用程序,我正在尝试使用gvisGauge.

我已经成功地将它们显示在单独的选项卡面板中,并且也在同一个选项卡面板中的一个下方。

但我想并排显示它们,即在同一选项卡中水平对齐。我怎样才能做到这一点?尝试搜索选项,但找不到任何选项。

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

用户界面

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

服务器.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));  

})


})
4

1 回答 1

1

您可以使用 column 指定布局,也可以使用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))
于 2014-12-18T08:19:56.447 回答