2016-05-18 5 views
1

this questionから採用されている以下のコードは、テキストの折り返しのドロップダウンを防ぎ、すべてのドロップダウンの幅を設定します。光沢のあるselectInputでドロップダウンの幅をカスタマイズします

selectInputのドロップダウンの幅をカスタマイズする方法はありますか?私はあなたの権利を理解していれば

library(shiny) 

ui <- (fluidPage(
    sidebarLayout(
    sidebarPanel(
     selectInput("userInput","Select User", c(1,2,3), 
        selected=1), 
     selectInput("LongInput", "Long Strings", c("This is a long long string that is long.", 
               "This is a long long string that is longer.")) 
    ), 

    # allows for long texts to not be wrapped, and sets width of drop-down 
    tags$head(
     tags$style(HTML(' 
         .selectize-input { 
         white-space: nowrap; 
         } 
         .selectize-dropdown { 
         width: 660px !important; 
         }' 
      ) 
      ) 
     ) 
     ) 
    )) 

server <- function(input, output, session) {} 

shinyApp(ui, server) 
+0

を試してみてください? – Batanichek

+0

確かに、または各ドロップダウンの幅をカスタマイズしたい –

答えて

3

あなたは

library(shiny) 

ui <- (fluidPage(
    sidebarLayout(
    sidebarPanel(
     selectInput("userInput","Select User", c(1,2,3), 
        selected=1), 
     selectInput("LongInput", "Long Strings", c("This is a long long string that is long.", 
               "This is a long long string that is longer.")) 
    ), 

    # allows for long texts to not be wrapped, and sets width of drop-down 
    tags$head(
     tags$style(HTML(' 
         .selectize-input { 
         white-space: nowrap; 
         } 
         #LongInput + div>.selectize-dropdown{ 
         width: 660px !important; 
         } 
         #userInput + div>.selectize-dropdown{ 
              width: 300px !important; 
         } 
         ' 
      ) 
    ) 
    ) 
    ) 
    )) 

server <- function(input, output, session) {} 

shinyApp(ui, server) 

そのようなものは、例えば更新 あなたも行うことができます

それdunamic userInput

ためLongInputと300ピクセルのため660pxに設定する必要がありますあなたは入力名とサイズのdfを持っています

df1=data.frame(name=c("LongInput","userInput"),px=c(600,300)) 

だから、あなたが長いだけのために、ドロップダウンの幅を変更したい

library(shiny) 

ui <- (fluidPage(
    sidebarLayout(
    sidebarPanel(
     selectInput("userInput","Select User", c(1,2,3), 
        selected=1), 
     selectInput("LongInput", "Long Strings", c("This is a long long string that is long.", 
               "This is a long long string that is longer.")) 
    ), 

    uiOutput("din_css") 

    ) 
    )) 

server <- function(input, output, session) { 
    df1=data.frame(name=c("LongInput","userInput"),px=c(600,300)) 

output$din_css=renderUI({ 
    tags$head(
     tags$style(HTML(paste0(' 
         .selectize-input { 
         white-space: nowrap; 
         }', 
         paste(apply(df1,1,function(i){ 
          paste0("#",i[["name"]],"+ div>.selectize-dropdown{ 
          width: ",i[["px"]],"px !important; 
          }") 
         }) 
         ,collapse='/n')  ) 
    ) 
    ) 
    ) 
    }) 
} 

shinyApp(ui, server) 

+0

これはどのように各ドロップダウンに合わせられますか? –

+0

hmm(私はあなたには分からないかもしれません).. 1つの 'selectize-dropdown'のためだけの幅を変更します..あなたのそれぞれのことを意味します(以前のバージョンはすべて(それぞれ)' selectize-dropdown'の幅を設定します) – Batanichek

+0

I 'どのように私はそれをより明確にすることができますか分からない。私はドロップダウンごとに異なる幅を設定したいと思います。 –

関連する問題