RStudio Shiny 动态选择 [英] RStudio Shiny dynamic selectize
问题描述
在我的 RStudio Shiny 中,我在 server.R
中找到了 selectInput
,在 ui.R
上我得到了一个 tags
语句来改变选择框的宽度和高度.
In my RStudio Shiny, I got my selectInput
inside my server.R
, and on ui.R
I got a tags
statement to change the width and height of the select box.
它在页面加载时工作,但当我进入单一类型时它会恢复到默认大小.任何想法如何解决它?
It works when the page is loaded, but it reverts to the default size when I got to the single type. Any ideas how to solve it?
在 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 上
On 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')
})
# [...]
当用户从 multiple
切换到 single
时,是否有任何想法如何应用 tags
命令?
Any ideas how to apply the tags
command also when the user switches from multiple
to single
?
推荐答案
您还需要动态添加 css.要定位选择输入,您需要定位 select#dataset + .selectize-control
而不是 select#dataset
You need to add the css dynamically also. To target the selectize input you need to target select#dataset + .selectize-control
rather then 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
:
or have two seperate CSS entries one for the select
and one for the 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'))
})
}
))
这篇关于RStudio Shiny 动态选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!