我正在研究闪亮的应用,我试图使用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));
})
})
答案 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))