我需要一些帮助我是Shiny世界的新手,并且陷入了可能非常基本的事情。这是我的ui.R和server.R代码
shinyUI(
pageWithSidebar(
headerPanel("Hello Shiny R..."),
sidebarPanel(
sliderInput(inputId="age", label="Age", min=1, max=99, value=24, step=1, animate=TRUE),
numericInput(inputId="height", label="Height (cm)", min=0, max=300, value=160, step=5),
numericInput(inputId="weight", label="Weight (kg)", min=0, max=500, value=100, step=5),
radioButtons(inputId="gender", label="Gender", choices=c("Male", "Female"), selected="Male", inline=TRUE),
textInput(inputId="name", label="Full Name"),
submitButton(text="Apply")
),
mainPanel(
h1("BMI Calculator"),
p("Name:"),
textOutput("name"),
p("Age:"),
textOutput("age"),
p("Gender:"),
textOutput("gender"),
p("BMI:"),
textOutput("bmi")
)
)
)
shinyServer(
function(input, output) {
output$name <- renderText({input$name})
output$age <- renderText({input$age})
output$gender <- renderText({input$gender})
weight <- renderText({as.numeric(input$weight)})
height <- renderText({as.numeric(input$height)})
output$bmi <- weight / (height * height)
}
)
当我执行runApp()时,这就是我所得到的:
Error in height * height : non-numeric argument to binary operator
答案 0 :(得分:1)
确定!我通过用反应函数替换渲染来解决这个特定情况。
weight <- reactive({input$
height <- reactive({input$height /
output$bmi <- renderText({weight() / (height() * height())})
但这并不能解释renderText函数的错误。