簡體   English   中英

閃亮:標簽位置,textInput

[英]Shiny: Label position, textInput

假設我有一個非常簡單的應用程序,只有8個輸入分組在2個面板中(4個輸入| 4個輸入-參見下面的圖片),然后基於這些,我繪制了一個小圖(簡單)。

我要制作的面板

我面臨的問題是我只希望第一個面板的標簽位於textInput框的左側。

例如(請原諒我草率的圖像編輯!)

在此處輸入圖片說明

有什么建議嗎?

圖1的我的MWE輸出:

library(shiny)
ui<-shinyUI(fluidPage(
  wellPanel(
    tags$style(type="text/css", '#leftPanel { max-width:300px; float:left;}'),
    id = "leftPanel",
    textInput("Population1000", 'Population 1000',"15"),
    textInput("Area1000",'Area  1000', "20"),
    textInput("GNI1000", 'GNI 1000', "2314"),
    textInput("GDP1000", "GDP 1000", "1000")
  ),
  wellPanel(
    tags$style(type="text/css", '#RightPanel { max-width:300px; float:left;}'),
    id = "RightPanel",
    textInput("Population2000", 'Population 2000',"15"),
    textInput("Area2000",'Area 2000', "20"),
    textInput("GNI2000", 'GNI 2000', "2314"),
    textInput("GDP2000", "GDP 2000", "1000")
  )
)
)
server<-shinyServer(function(input, output) {NULL})
shinyApp(ui,server)

嗨,您可以嘗試使用Bootstrap的水平形式 ,看下面的代碼,它創建3列,每列4個寬度。 您可以在class = "col-sm-4 control-label"為標簽更改寬度,在輸入中為width = 4更改寬度。

library("shiny")
ui <- fluidPage(

  fluidRow(
    column(

      width = 4,

      tags$form(
        class="form-horizontal",

        tags$div(
          class="form-group",
          tags$label(class = "col-sm-4 control-label", `for` = "Population1000", br(), "Population"),
          column(width = 4, textInput(inputId = "Population1000", label = "Year 1000", value = "15")),
          column(width = 4, textInput(inputId = "Population2000", label = "Year 2000", value = "15"))
        ),

        tags$div(
          class="form-group",
          tags$label(class = "col-sm-4 control-label", `for` = "Area1000", "Area"),
          column(width = 4, textInput(inputId = "Area1000", label = NULL, value = "20")),
          column(width = 4, textInput(inputId = "Area2000", label = NULL, value = "20"))
        ),

        "..."

      )
    )
  )

)

server <- function(input, output) {

}

shinyApp(ui = ui, server = server)

結果:

在此處輸入圖片說明

PS:您不應將相同的ID用於輸入。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM