如何在Shiny中绘制来自selectInput()函数的选定输入? [英] How to plot selected input from selectInput() function in shiny?
本文介绍了如何在Shiny中绘制来自selectInput()函数的选定输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在闪亮地使用以下两个输入函数代码:
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)
和
selectInput("investerVisu", label="SELECT INVESTOR", choices = list("Informed" = "inf", "Noise" = "noise"), selected = "inf", multiple = TRUE)
现在,我的任务是,如果用户选择了 Full和 Informed,那么我的代码应将数据集中的 InformedFull列打印代码我该如何处理?我的数据集如下:
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:
我已经做了ggplot代码,看起来像这样:
I already did the ggplot code, that looks like this:
ggplot(data = OLS.Data, aes(x=OLS.Data$Date, y=...))+geom_line()
因此,我放置...的位置应基于selectInput的展位选择,即我数据集的正确列。
So where I placed the ... their should be based on the booth selection of my selectInput, be the correct column of my dataset.
我的UI框如下:
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)
),
和我的服务器文件:
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)
})
}
推荐答案
找到解决方案:
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)
})
})
这篇关于如何在Shiny中绘制来自selectInput()函数的选定输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文