Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
350 views
in Technique[技术] by (71.8m points)

r - How to plot selected input from selectInput() function in shiny?

I am using the following two Input functions code in shiny:

selectInput("categoryVisu", label="SELECT CATEGORY", choices = list("Full" = "full", "Fact" = "fact", "Fact Positive" = "factpos", selected = "full", multiple = TRUE)

and

selectInput("investerVisu", label="SELECT INVESTOR", choices = list("Informed" = "inf", "Noise" = "noise"), selected = "inf", multiple = TRUE)

My task is now, if the user select for example "Full" and "Informed" than my code should take the column "InformedFull" from my dataset to print the code. How can I handle this? My DataSet looks like this:

Dataset

I already did the ggplot code, that looks like this:

ggplot(data = OLS.Data, aes(x=OLS.Data$Date, y=...))+geom_line()

So where I placed the ... their should be based on the booth selection of my selectInput, be the correct column of my dataset.

My UI Boxes looking like this:

  tabItem(tabName = "visu",
          fluidRow(
            box(
              title = "Controls-1", 
              status = "primary", 
              solidHeader = TRUE,
              width = 3,
              selectInput("categoryVisu", label="SELECT CATEGORY", choices = list("Full" = "Full", "Fact" = "Fact", "Fact Positive" = "Fact.Pos", "Fact Negative" = "Fact.Neg", "Emotions" = "Emotions", "Emotions Fact" = "EmotionsFact"), selected = "Full", multiple = TRUE)
            ),

            box(
              title = "Controls-2", 
              status = "primary", 
              solidHeader = TRUE,
              width = 3,
              selectInput("investerVisu", label="SELECT INVESTOR", choices = list("Informed" = "Informed", "Noise" = "Noise"), selected = "Informed", multiple = TRUE)
            ),

And my server file:

server <- function(input, output) {

  observeEvent(input$categoryVisu,{

    partA<-input$catagoryVisu
    partA<-as.character(partA)    

  })

  observeEvent(input$investerVisu,{

    partB<-input$investerVisu
    partB<-as.character(partB)

  })

  partC<-paste(partB,partA)

  DataFus<-OLS.Data$partC

  output$myPlot <- renderPlot({
    ggplot(data = OLS.Data, aes(x=OLS.Data$Date, y=OLS.Data$NYSE))+geom_line()+geom_line(data = OLS.Data,aes(x=OLS.Data$Date, y=DataFus),color="red")+geom_line(alpha = input$alphaVisu)
  })

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Solution found:

server <- function(input, output) {

  partA = NULL
  partB = NULL

  makeReactiveBinding("partA")
  makeReactiveBinding("partB")

  observeEvent(input$categoryVisu, { 
    partA<<-input$categoryVisu
    partA<<-as.character(partA)
  })

  observeEvent(input$investorVisu, { 
    partB<<-input$investorVisu
    partB<<-as.character(partB)
  })

  observe({
    PartC<-as.character(paste(partB,partA,sep=""))
    print(PartC)
      output$myPlot <- renderPlot({
        ggplot(data = OLS.Data, aes(x=OLS.Data$Date, y=OLS.Data$NYSE))+geom_line()+geom_line(data = OLS.Data,aes(x=OLS.Data$Date, y=OLS.Data[PartC]),color="red")+geom_line(alpha = input$alphaVisu)
      })
  })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...