2017-06-27 145 views
1

讓我們假設我有一個非常簡單的應用程序,只有8個輸入分組在2個面板(4輸入| 4輸入 - 見圖片波紋管),並基於這些,我繪製一個小圖(容易peasy )。閃亮:標籤位置,文本輸入

The panel I want to make

,我所面臨的問題是,我想有標籤只提供給第一面板,並在textInput框的左側。

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

enter image description here

什麼建議嗎?

我對圖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) 

回答

3

嗨,你可以嘗試使用引導的horizontal form,看看下面的代碼,它創建的每個寬度4 3列。您可以在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) 

結果:

enter image description here

PS:你不應該使用相同的ID進行輸入。

+0

嗨@Victorp,這確實是一個非常好的解決方案,但它不能解決我的問題,因爲我無法在面板中對條目進行分組 - 或類似的東西。基本上,每列應該代表一年(例如1000,2000),因此應該有區分列的方法(例如標題)。 (對不起,我不會在圖片中使它更清晰,我會做出更改) –

+1

最簡單的方法是在第一個輸入中放置一個標籤,並在左側的標籤中添加換行符。查看編輯 – Victorp

+0

精彩的,測試它,它的工作方式非常好。 –