Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于R Shining dashboard中的单选按钮进行打印_R_Shiny - Fatal编程技术网

基于R Shining dashboard中的单选按钮进行打印

基于R Shining dashboard中的单选按钮进行打印,r,shiny,R,Shiny,这是我的代码: ui <- fluidPage( radioButtons("dist", "Distribution type:", c("Sepal.Length" = "Length", "Sepal.Width" = "Width", "Petal.Length" = "Length")), plotOutput("distPlot") ) server <- func

这是我的代码:

ui <- fluidPage(
  radioButtons("dist", "Distribution type:",
               c("Sepal.Length" = "Length",
                 "Sepal.Width" = "Width",
                 "Petal.Length" = "Length")),
  plotOutput("distPlot")
)

server <- function(input, output) {
  output$distPlot <- renderPlot({
    dist <- switch(input$dist,
                   "Length" = plot(iris$Sepal.Length),
                   "Width" = plot(iris$Sepal.Width),
                   "Length" = plot(iris$Sepal.Length))

    plot(dist)
  })
}

shinyApp(ui, server)
}

ui您不需要绘制指定的函数,因为
switch
it0已经在这样做了

server <- function(input, output) {
  output$distPlot <- renderPlot({
  switch(input$dist,
               "Length" = plot(iris$Sepal.Length),
               "Width" = plot(iris$Sepal.Width),
               "Length" = plot(iris$Sepal.Length))
           })
}

如何使用
par(mfrow=c(1,2))
为每个按钮绘制两个图?我不知道您想要实现什么。?每个按钮有两个绘图?但您只在“服务器”上定义了一个绘图。要为选项创建两个绘图,我可以想到两个备选方案:1)在UI中添加另一个“plotOutput”,在服务器中呈现另一个绘图。2) 使用“ggplot”和“facet”根据变量进行复制。谢谢@David Jorquera,我将尝试使用ggplot。
server <- function(input, output) {
  output$distPlot <- renderPlot({
  par(mfrow=c(1,2))
  switch(input$dist,
               "Length" = plot(iris$Sepal.Length),
               "Width" = plot(iris$Sepal.Width),
               "Length" = plot(iris$Sepal.Length))
  switch(input$dist,
               "Length" = plot(iris$Sepal.Length),
               "Width" = plot(iris$Sepal.Width),
               "Length" = plot(iris$Sepal.Length))
       })