在我的RStudio Shiny中,我在我的selectInput
中找到了server.R
,在ui.R
上我获得了tags
语句来更改选择框的宽度和高度。
它在页面加载时有效,但当我到达单一类型时它恢复到默认大小。任何想法如何解决?
关于ui.R
# [...]
,div(class="span6"
,radioButtons("viz_multiple", "Select Type:",
c("Select From List (can use Up/Down + Enter)" = "multiple",
"Search One (Delete then type keyword)" = "single")
)
)
)
,div(class='row-fluid'
,div(class='span12', uiOutput("image_list"))
,tags$head(tags$style(type="text/css", "select#iimage_list { width: 1000px; height: 40px; }"))
)
# [...]
在server.R
上# [...]
output$image_list <- renderUI({
imagelist = image_ls()
iimage_list <- as.vector(sort(unique(as.character(imagelist)),decreasing=TRUE))
length_list = length(iimage_list)
selectInput("iimage_list",paste0("samples (",length_list,")"),choices=iimage_list, selectize = input$viz_multiple == 'single')
})
# [...]
当用户从tags
切换到multiple
时,有关如何应用single
命令的任何想法吗?
答案 0 :(得分:2)
您还需要动态添加css。要定位选择性输入,您需要定位select#dataset + .selectize-control
,而不是select#dataset
库(有光泽)
runApp(list(
ui = bootstrapPage(
radioButtons("viz_multiple", "Select Type:",
c("Select From List (can use Up/Down + Enter)" = "multiple",
"Search One (Delete then type keyword)" = "single")
)
, uiOutput("myUI")
),
server = function(input, output){
output$myUI <- renderUI({
myCSS <-if(input$viz_multiple == 'single'){
tags$style(type="text/css", "select#dataset + .selectize-control{ width: 1000px; height: 40px; }")
}else{
tags$style(type="text/css", "select#dataset { width: 1000px; height: 40px; }")
}
tagList(
selectInput('dataset', 'Choose Dataset', c('mtcars', 'iris'), selectize = (input$viz_multiple == 'single'))
, myCSS
)
})
}
))
或有两个单独的CSS条目,一个用于select
,另一个用于selectize
:
library(shiny)
runApp(list(
ui = bootstrapPage(
radioButtons("viz_multiple", "Select Type:",
c("Select From List (can use Up/Down + Enter)" = "multiple",
"Search One (Delete then type keyword)" = "single")
)
, uiOutput("myUI")
, tags$style(type="text/css", "select#dataset + .selectize-control{ width: 1000px; height: 40px; }")
, tags$style(type="text/css", "select#dataset { width: 1000px; height: 40px; }")
),
server = function(input, output){
output$myUI <- renderUI({
selectInput('dataset', 'Choose Dataset', c('mtcars', 'iris'), selectize = (input$viz_multiple == 'single'))
})
}
))