并非所有给定的 selectInput 选项都以闪亮的 R 显示
Posted
技术标签:
【中文标题】并非所有给定的 selectInput 选项都以闪亮的 R 显示【英文标题】:Not all given selectInput choices are shown in shiny R 【发布时间】:2019-08-19 05:08:11 【问题描述】:我对一个非常简单的Shiny
应用程序有疑问。 selectInput
选项的数量似乎受到限制,我只能在问题 e 上显示 6 个选项:药物。我希望有更多选择,但无论我如何选择,结果都是一样的。
我在这里提供整个代码
library(tidyverse)
library(shiny)
library(rsconnect)
ui <- fluidPage(
# Sidebar layout with a input and output definitions
sidebarLayout(
# Inputs
sidebarPanel(
# Select variable for crtieria 1
selectInput(inputId = "a",
label = "Delay from initial drug component intake to onset of reaction (index day)",
choices = c("From 5 to 28 days"=3, "From 29 to 56 days"=2, "From 1 to 4 days"=1, ">56 Days"=-1, "Drug started on or
after the index day"=-3),
selected = "From 5 to 28 days"),
#select variable for criteria 2
selectInput(inputId = "b",
label = "Drug present in the body on index day",
choices = c("Drug continued up to index day or stopped at a time point less than five times the elimination half-life before the index day"=0,
"Drug stopped at a time point prior to the index day by more than five times the elimination half-life but liver or kidney function alterations or suspected drug interactions are present"=-1,
"Drug stopped at a time point prior to the index day by more than five times the elimination half-life, without liver or kidney function alterations or suspected drug interactions"=-3),
selected = "Drug continued up to index day or stopped at a time point less than five times the elimination half-life before the index day"),
#criteria 3
selectInput(inputId = "c",
label = "Prechallenge-rechallenge",
choices = c("SJS-TEN after use of same drug"=4,
"SJS-TEN after use of similar drug or other reaction with same drug"=2,
"Other reaction after use of similar drug"=1, "No known previous exposure to this drug"=0, "Exposure to this drug without any reaction (before or after reaction)"=-2),
selected = "SJS-TEN after use of same drug"),
#criteria 4
selectInput(inputId = "d",
label = "Dechallenge",
choices = c("Drug stopped (or unknown)"=0,
"Drug continued without harm"=-2),
selected = "Drug stopped (or unknown)"),
selectInput(inputId = "e",
label = "Drug",
choices = c("5-FU" = 0, "abacavir" = 0, "acamprosate" = 0, "acarbose" = 0, "aceclofenac" = 1, "acemetacin" = 0, "acepromazine" = 0, "aceprometazine" = 0, "acetylcysteine" = 1, "acetyldigoxin" = 0, "acetylsalicylic acid (aspirin)" = -1, "aciclovir" = 1),
selected = "5-FU"),
#criteria 6
selectInput(inputId = "f",
label = "Other cause",
choices = c("At least one other druf with score >3"=-1,"No other drug with score >3"=0),
selected = "At least one other druf with score >3")
),
# Outputs
mainPanel(
textOutput(outputId = "ALDEN")
)
)
)
# Define server function required to create the scatterplot
server <- function(input, output)
# print result
output$ALDEN <- renderPrint(
paste0("ALDEN score = ",as.numeric(input$a)+as.numeric(input$b)+as.numeric(input$c)+as.numeric(input$d)+as.numeric(input$e)+as.numeric(input$f))
)
# Create a Shiny app object
shinyApp(ui = ui, server = server)
【问题讨论】:
【参考方案1】:这不是错误,您正在使用重复值作为选择。基本上,您对selectInput(inputId = "e", ...)
的选择是具有以下值的向量:c(0,0,0,0,1,0,0,0,1,0,-1,1)
。 selectInput
将选择分解为 c(0,1,-1)
的向量,这导致只有三个可见的选择选项。
我不确定为什么不能显示重复的选择。但是,您可以将选项 selectize
设置为 FALSE
并且所有选项都将起作用。然而,这会改变下拉菜单的外观。
selectInput(inputId = "e",
selectize = FALSE,
label = "Drug",
choices =
c("5-FU" = 0, "abacavir" = 0, "acamprosate" = 0, "acarbose" = 0, "aceclofenac" = 1, "acemetacin" = 0, "acepromazine" = 0, "aceprometazine" = 0,
"acetylcysteine" = 1, "acetyldigoxin" = 0, "acetylsalicylic acid (aspirin)" = -1, "aciclovir" = 1),
selected = "5-FU"),
【讨论】:
以上是关于并非所有给定的 selectInput 选项都以闪亮的 R 显示的主要内容,如果未能解决你的问题,请参考以下文章
闪亮的 selectInput 'Select All' 层次结构
如何从 R 中的 selectInput 函数中一次选择所有输入
Shiny - 更改 selectInput() 中的选项数量