Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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)
      })
  })

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...