【发布时间】:2021-05-28 02:22:12
【问题描述】:
我想做的是根据用户选择的内容为面板生成一个标题。例如,如果用户选择“z”的单选按钮,我希望面板的标题显示“z”。
我知道我可以使用很多 conditionalPanel 语句到达那里,例如 conditionalPanel(condition="input.choice_crit==1",h3("First Choice")) 或其他什么,但使用起来会更优雅我已经放入单选按钮选择列表的名称。如果我在某个时候添加其他内容,更新会更容易。
所以这段代码可以工作,但显然不是动态的。有没有办法将 [3] 替换为单选按钮中已选择的任何内容,以便 h3() 填充选择时从choice_crit 中选择的适当名称?
library(shiny)
choice_crit <- c(1, 2, 3, 4)
names(choice_crit) <- c("z","t","\U1D6D8\U00B2","F")
# Define UI
ui <- fluidPage(
# Sidebar
sidebarLayout(
sidebarPanel(
h3(names(choice_crit[3])),
radioButtons(inputId = "crit_select",label = "Select the statistic:",choices = choice_crit),
),
# Main output
mainPanel(
)
)
)
# Define server logic
server <- function(input, output) {
}
# Run the application
shinyApp(ui = ui, server = server)
【问题讨论】: