çµæ„Ÿæ¥è‡ªsolution我åªæ˜¯æƒ³çŸ¥é“是å¦å¯ä»¥å›žåˆ°æŒ‰é’®ï¼†ï¼ƒ34; All"å–消选ä¸æ‰€æœ‰åˆ—å称åŽã€‚当然,我å¯ä»¥ç®€å•åœ°å¼€å‘else if
函数:
if(input$radio == "All"){
hw
}
else if (length(input$show_vars) == 0){
hw
}
else {
hw[,input$show_vars,drop=FALSE]
}
并且结果计算diamonds
æ•°æ®é›†ä¸çš„所有列,但在radioButtonsé¢æ¿ä¸æ²¡æœ‰ä»»ä½•å˜åŒ–(å³ï¼†ï¼ƒ34;手动选择"按钮ä»å°†æ‰“开)。相å,我想在å–消选ä¸æ‰€æœ‰checkboxGroupInput选项åŽè‡ªåŠ¨æ›´æ”¹radioButton。
ui.R
library(shiny)
shinyUI(fluidPage(
title = 'Examples of DataTables',
sidebarLayout(
sidebarPanel(
radioButtons(
inputId="radio",
label="Variable Selection Type:",
choices=list(
"All",
"Manual Select"
),
selected="All"),
conditionalPanel(
condition = "input.radio != 'All'",
checkboxGroupInput(
'show_vars',
'Columns in diamonds to show:',
choices=names(hw),
selected = "carat"
)
)
),
mainPanel(
verbatimTextOutput("summary"),
tabsetPanel(
id = 'dataset',
tabPanel('hw', dataTableOutput('mytable1'))
)
)
)
))
server.R (使用我的其他功能):
library(shiny)
library(ggplot2)
data(diamonds)
hw <- diamonds
shinyServer(function(input, output) {
Data <- reactive({
if(input$radio == "All"){
hw
}
else if (length(input$show_vars) == 0){
hw
}
else {
hw[,input$show_vars,drop=FALSE]
}
})
output$summary <- renderPrint({
## dataset <- hw[, input$show_vars, drop = FALSE]
dataset <- Data()
summary(dataset)
})
# a large table, reative to input$show_vars
output$mytable1 <- renderDataTable({
Data()
## hw[, input$show_vars, drop = FALSE]
})
})
ç”案 0 :(得分:1)
也许您æ£åœ¨å¯»æ‰¾æ›´æ–°å•é€‰æŒ‰é’®çš„方法 http://shiny.rstudio.com/reference/shiny/latest/updateRadioButtons.html
ç”案 1 :(得分:0)
æ„Ÿè°¢Rohit Das我是我想åšçš„。
我的æ„æ€æ˜¯ï¼Œ
data(diamonds)
hw <- diamonds
shinyServer(function(input, output,session) {
Data <- reactive({
if(input$radio == "All"){
hw
}
else if (length(input$show_vars) == 0){
updateRadioButtons(session,
"radio",
"Variable Selection Type:",
choices=list("All","Manual Select"),
selected = "All")
updateCheckboxGroupInput(session,
'show_vars',
'Columns in diamonds to show:',
choices=names(hw),
selected = "carat")
}
else {
hw[,input$show_vars,drop=FALSE]
}
})
ç”案 2 :(得分:0)
shinyWidgets
库有一个很好的函数å«pickerInput()
,附带一个“全选/å–消全选â€åŠŸèƒ½ã€‚ç»è¿‡å¤§é‡ç ”究,我å‘现这是唯一内置æ¤åŠŸèƒ½çš„Shiny输入:
链接到网站:https://dreamrs.github.io/shinyWidgets/index.html