J'essaie actuellement une application brillante qui génère le résumé d'une régression linéaire simple et un graphique. Pour les deux scénarios, j'aimerais que l'utilisateur sélectionne les variables indépendantes et dépendantes des colonnes de la table et utilise ces mêmes entrées pour exécuter la régression et le graphique. En ce moment je ne peux pas comprendre comment passer l'entrée sélectionnée par l'utilisateur dans l'intrigue pour un affichage. Quelqu'un peut-il aider, merci d'avance!Passage de l'entrée réactive dans l'axe d'un graphique en R Shiny
Voici les données de l'échantillon:
AvgIR SumCount AvgLTV AvgGFEE AvgRTC Date
1: 0.04106781 180029 0.753180543134717 0.002424778 319.6837 2015-10-01
2: 0.04036154 160061 0.738038310394162 0.002722529 312.6314 2015-11-01
3: 0.04001407 145560 0.739287372904644 0.002425912 313.0351 2015-12-01
4: 0.04034078 147693 0.739693214979721 0.002600640 315.0238 2016-01-01
5: 0.04055688 142545 0.734515977410642 0.002449523 310.3950 2016-02-01
6: 0.04007467 176344 0.735780463185592 0.002459228 309.9615 2016-03-01
Voici ui:
ui <- fluidPage(
headerPanel("Regression and Time Series Analysis"),
sidebarPanel(
p("Select a Dependent Variable"),
selectInput(inputId = "DepVar", label = "Dependent Variables", multiple = FALSE, choices = names(RegData2)),
p("Select input(s) for the Independent Variable(s)"),
selectInput(inputId = "IndVar", label = "Independent Variables", multiple = FALSE, choices = list("SumCount", "AvgIR", "AvgLTV", "AvgGFEE", "AvgRTC", "Date"), selected = "AvgLTV"),
p("Summary of Regression"),
verbatimTextOutput(outputId = "RegSum")
),
mainPanel(
verbatimTextOutput(outputId = "IndPrint"),
verbatimTextOutput(outputId = "DepPrint"),
verbatimTextOutput(outputId = "test"),
verbatimTextOutput(outputId = "xaxis"),
verbatimTextOutput(outputId = "yaxis"),
tableOutput("table"),
plotlyOutput("graph")
)
)
Voici le serveur:
server <- function(input, output) {
lm1 <- reactive({lm(reformulate(input$IndVar, input$DepVar), data = RegData2)})
Ind <- reactive({input$IndVar})
Dep <- reactive({input$DepVar})
plotdata <- reactive({as.data.frame(RegData2[, c(which(names(RegData2) == Ind()), which(names(RegData2) == Dep())), with = FALSE])})
xaxis <- reactive({names(RegData2)[which(names(RegData2) == Ind())]})
yaxis <- reactive({names(RegData2)[which(names(RegData2) == Dep())]})
# xaxisN <- reactive({names(xaxis())})
# yaxisN <- reactive({names(yaxis())})
output$table <- renderTable({
x<-plotdata()
#RegData2[, c(which(names(RegData2) == Ind()), which(names(RegData2) == Dep())), with = FALSE]
})
output$graph <- renderPlotly({
#xaxis <- paste(input$IndVar)
#yaxis <- paste(input$DepVar)
#THIS ONE WORKS, but isn't reactive
#plot<-plot_ly(plotdata(), x = ~AvgLTV, y = ~AvgIR, mode = "markers", type = "scatter")
#THIS ONE DOESN'T WORK, is reactive
plot<-plot_ly(plotdata(), x = ~input$IndVar, y = ~input$DepVar, mode = "markers", type = "scatter")
})
output$IndPrint <- renderPrint({str(Ind())})
output$test <- renderPrint({str(plotdata())})
output$xaxis <- renderPrint({xaxis()})
output$yaxis <- renderPrint({yaxis()})
output$DepPrint <- renderPrint({input$DepVar})
output$RegSum <- renderPrint({summary(lm1())})
}
shinyApp(ui = ui, server = server)
Pas familier avec ', avec = FALSE' dans le réactif' plotdata'. Qu'est-ce qui est censé faire? Je reçois une erreur de toute façon. –
Merci pour la réponse ci-dessous, votre solution a fonctionné! Le "with = FALSE" pour data.tables sous-ensembles les données à seulement les deux colonnes que j'ai entré dans la partie "j" de l'énoncé pour les valeurs de caractères. Par exemple. [i, j, par] Avec la déclaration suivante: RegData2 [, c (qui (noms (RegData2) == "AvgLTV"), qui (noms (RegData2) == "AvgIR")), avec = FALSE] il retourne ceci: AvgLTV AvgIR 1: ,753180543134717 0,04106781 2: ,738038310394162 0,04036154 3: ,739287372904644 0,04001407 sans "avec = FALSE", il renvoie la position des têtes de colonne: [1] 3 1 – Jst2Wond3r
Ok. Je tiens juste à souligner que vous pouvez upvote maintenant aussi :) –