【发布时间】:2015-09-22 15:00:20
【问题描述】:
我很难在 Shiny Apps 中使用反应式表达。我正在从滑块输入创建一个饼图。这一切都很好,但是,标签重叠。为了避免这种情况,当输入为零时,我想要标签“”。困难在于我无法在 if-then 语句中嵌入反应式表达式。
这是一个 MWE...
文件“ui.R”...
library(shiny)
shinyUI(fluidPage(
titlePanel("Exposure to English calculator"),
sidebarLayout(
sidebarPanel(
h3("Sleeping"),
sliderInput("sleep", "How long does your child sleep every day?",
min=0, max=15, value=0, step = 0.5),
h3("School"),
sliderInput("school", "How long does your child spend in school?",
min = 0, max = 50, value=0, step = 0.5)
),
mainPanel(
plotOutput("plot")
)
)
))
文件服务器.R...
library(shiny)
values <- c(1,2)
# Define server logic for slider examples
shinyServer(function(input, output) {
total_sleep <- reactive({7*input$sleep})
pieLabels<-c("sleep", "school", "other")
if(total_sleep() == 0) {
pieLabels[1] <- ""
}
output$plot <- renderPlot({
pie(c(total_sleep(), input$school, 50),
labels = pieLabels,
col = c("deepskyblue", "orange"),
height = 1500
)
})
})
编译由于“if”表达式而崩溃,即使我在它后面加上了括号,以表明它是从反应式表达式派生的。
提前致谢。
【问题讨论】: