2017-08-03 66 views
0

我在Shiny Dashboard页面上的四个框中制作了四个图。我希望基于Slider的输入从1到4的范围内动态地在一个框中表示所有四个图。所有图都不同并且不相关。我想知道基本的语法来做到这一点。谢谢根据滑块输入更新Shiny Plots

+0

https://stackoverflow.com/help/mcve –

回答

1

由于@猪排评论你应该检查出the website which is going to help you in asking the question on stackoverflow

因为你是这个社区中的新人,我会给你一个提示,告诉你如何用滑块输入更新闪亮的图。

下面是代码:

library(shiny) 
library(shinydashboard) 
library(ggplot2) 

data <- data.frame(x=c(1,2,3,4),y=c(10,11,12,13)) 
ui <- dashboardPage(
    dashboardHeader(), 
    dashboardSidebar(sliderInput("slider","Slider", min=1, max=4, step =1, value=1)), 
    dashboardBody(
    fluidRow(column(6,plotOutput('plot1'),plotOutput('plot2')), 
      column(6,plotOutput('plot3'),plotOutput('plot4')) 
         ))) 
server <- function(input, output, session) { 
    output$plot1 <- renderPlot({ 
    ggplot(data,aes_string(x=input$slider, y="y"))+geom_point(size=5) 
    }) 
    output$plot2 <- renderPlot({ 
    ggplot(data,aes_string(y=input$slider, x="y"))+geom_point(size=5) 
    }) 

    output$plot3 <- renderPlot({ 
    ggplot(data,aes_string(y=input$slider, x="y"))+geom_line(size=5) 
    }) 

    output$plot4 <- renderPlot({ 
    ggplot(data,aes_string(x=input$slider, y="y"))+geom_line(size=5) 
    }) 
} 

shinyApp(ui, server) 

下一次不要忘记创建一些示例代码和样本数据!

+0

您好Mal_a,首先非常感谢您的努力,我还有一个疑问,我希望您能解决它。真的很感激。请检查此链接:https://stackoverflow.com/questions/45483350/dynamic-hover-to-represent-data-population-in-r-tool – AK94