基于这篇文章: create plots based on radio button selection R Shiny
我想要一个不同的绘图输出,具体取决于用户选择的无线电选项,并使用滑块输入调整委员会的数量。
滑块输入不起作用,我没有意识到如何解决问题。 非常感谢您的帮助!
这是我的代码:
library(shiny)
library(Cubist)
plotType <- function(x, type, committe) {
switch(type,
Cond = dotplot(finalModel, what = "splits"),
Coeff = dotplot(finalModel, what = "coefs"))
}
ui <- shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
radioButtons(inputId = "ptype", label = "Select the plot", choices = c("Cond", "Coeff")),
sliderInput(inputId = "commit", min=1, max = 25, value = 2)
),
mainPanel(
plotOutput("plots"))
)))
server <- shinyServer(function(input, output) {
output$plots <-renderPlot({
plotType(finalModel, input$ptype, input$commit)
})
})
shinyApp(ui = ui, server = server)
答案 0 :(得分:0)
请务必将lable
添加到sliderinput
:
library(shiny)
plotType <- function(x, type, committe) {
switch(type,Cond = dotplot(finalModel, what = "splits"),Coeff = dotplot(finalModel, what = "coefs"))
}
ui <- shinyUI(fluidPage(
sidebarLayout(
sidebarPanel(
radioButtons(inputId = "ptype", label = "Select the plot", choices = c("Cond", "Coeff")),
sliderInput(inputId = "commit","", min=1, max = 25, value = 2)
),
mainPanel(
plotOutput("plots"))
)))
server <- shinyServer(function(input, output) {
output$plots <- renderPlot({
plotType(finalModel, input$ptype, input$commit)
})
})
shinyApp(ui = ui, server = server)
答案 1 :(得分:-1)
此行末尾不需要逗号:
sliderInput(inputId = "commit", min=1, max = 25, value = 2),
应该是:
sliderInput(inputId = "commit", min=1, max = 25, value = 2)