我是一名数学科学专业课程的学生,有时我想重新创建一个教师展示的示例,让我的手用于R编码等等, 现在我正在创建那个闪亮的应用程序并使用闪亮的sliderinput 2值,但剧情总是说“错误:无效的参数” 我发现滑块中的错误,因为我用固定的值更改它,它工作正常,所以这里是代码,如果我做错了,希望你公平。
那是ui.R
library(shiny)
shinyUI(fluidPage(
titlePanel("Plot Random Number"),
sidebarLayout(
sidebarPanel(
numericInput(
"numeric",
"How Many Random Numbers Should be Plotted",
value = 1000,
min = 1,
max = 1000,
step = 1
),
sliderInput(
"sliderX",
"Pick minimum and maximum X values",
min = -100,
max = 100,
value = c(-50, 50)
),
sliderInput(
"SliderY",
"Pick minimum and maximum Y values",
min = -100,
max = 100,
value = c(-50, 50)
),
checkboxInput("show_xlab", "Show/Hide X Axis Label", value = TRUE),
checkboxInput("show_ylab", "Show/Hide Y Axis Label", value = TRUE),
checkboxInput("show_title", "Show/Hide plot title", value = TRUE)
),
mainPanel(h3("Graph of Random Points"),
plotOutput("plot1"))
)
))
那就是server.R
library(shiny)
library(ggplot2)
shinyServer(function(input, output) {
output$plot1 <- renderPlot({
set.seed(12345)
num.of.points <- input$numeric
minX <- input$sliderX[1] #i know the error here
maxX <- input$sliderX[2] #but i guess that's the right way though
minY <- input$SliderY[1] #so is anything has changed !
maxY <- input$sliderY[2]
dataX <- runif(num.of.points, minX, maxX)
dataY <- runif(num.of.points, minY, maxY)
labx <- ifelse(input$show_xlab, "X Axis", "")
laby <- ifelse(input$show_ylab, "Y Axis", "")
main.title <- ifelse(input$show_title, "Title", "")
qplot(
x = dataX,
y = dataY,
xlab = labx,
ylab = laby,
main = main.title,
xlim = c(-100, 100),
ylim = c(-100, 100)
)
})
})
答案 0 :(得分:1)
您在此处输错了变量名称:
minX <- input$sliderX[1] maxX <- input$sliderX[2] minY <- input$SliderY[1] maxY <- input$sliderY[2]
变量名称区分大小写。
在输入中,您已定义sliderX
和SliderY
。
我建议将输入重命名为sliderY
,并将minY
更改为:
minY <- input$sliderY[1]