If statement 使用if和Else在R中呈现文本时出现问题
我正在尝试建立一个闪亮的应用程序,允许个人选择一个选项,然后如果他们选择另一个选项,就会出现一个特定的文本 目前,我遇到了一个错误,我尝试使用if-else,我对闪亮和R都是新手,所以我在代码上很挣扎 我尝试过使用一个反应性的x,但也无法让它工作,因为这不是数字If statement 使用if和Else在R中呈现文本时出现问题,if-statement,shiny,rendering,If Statement,Shiny,Rendering,我正在尝试建立一个闪亮的应用程序,允许个人选择一个选项,然后如果他们选择另一个选项,就会出现一个特定的文本 目前,我遇到了一个错误,我尝试使用if-else,我对闪亮和R都是新手,所以我在代码上很挣扎 我尝试过使用一个反应性的x,但也无法让它工作,因为这不是数字 # Sidebar with a select input for number of bins sidebarLayout( sidebarPanel( selectInput(inputId = "Opti
# Sidebar with a select input for number of bins
sidebarLayout(
sidebarPanel(
selectInput(inputId = "Options",
label = "Option",
choices = c("Option 1","Option 2"))
),
# Show a text output
mainPanel(
textOutput(outputId = "ParticpantInformation1"),
textOutput(outputId = "ParticpantInformation2")
)),
# Define server logic required to rendertext
server <- function(input, output) {
if (input$Options=="Option 1") output$ParticpantInformation1 <- renderText("Option 1")
else output$ParticpantInformation2 <-renderText("Option 2")
#带有选择输入的边栏,用于输入箱子数量
侧边栏布局(
侧栏面板(
选择输入(inputId=“选项”,
label=“Option”,
选项=c(“选项1”、“选项2”))
),
#显示文本输出
主面板(
textOutput(outputId=“ParticpantInformation1”),
textOutput(outputId=“ParticpantInformation2”)
)),
#定义rendertext所需的服务器逻辑
服务器您不需要该if()
。您可以像这样直接参考用户选择:
library(shiny)
ui <- fluidPage(
# Sidebar with a select input for number of bins
sidebarLayout(
sidebarPanel(
selectInput(inputId = "Options",
label = "Option",
choices = list("Option 1" = "My option 1 text", "Option 2" = "My option 2 text"))
),
# Show a text output
mainPanel(
textOutput(outputId = "ParticpantInformation")
))
)
server <- function(input, output, session) {
output$ParticpantInformation <- renderText({input$Options})
}
shinyApp(ui = ui, server = server)
库(闪亮)
ui谢谢你非常有用,已经花了几个小时试图让这个工作你是受欢迎的!如果答案有帮助,请接受。