I've got a d3.js script as a R.js working perfectly when I run the preview option, but I can't get it run properly in RShiny. The inputs are not re-rendering the output and the colors are not how I set them in the js. I have a dataframe with multiple columns and I want to select the columns based on the user input to feed into the R2D3 function call in RShiny that will invoke the d3.js.
---I have the csv set up with id in one column (that will always be pulled), and value for all the other columns, even though they originally stand for values like "planet radius" etc... so I don't have to deal with changing the column names.
This code below is just the latest iteration of what I've tried. I've been through many things before like trying to make a separate reactive block for the input variable setting to a df variable which would later be called in the r2d3 function call with df(). I am out of options and out of mind at this point.
Is there something I'm missing like in the d3js script or in Rshiny? I've set up the script in the ui with includeScript() as I've seen on other posts.
the d3 script I'm using is here: https://rstudio.github.io/r2d3/articles/gallery/bubbles/
I've tried everything in my wheelhouse (which isn't much), I mean literally 20 hours spent on this and I can't get it to work.
library(shiny)
library(r2d3)
planets <- read.csv("grouped.csv")
columnList = c("Orbital Period [days]", "Orbital Semi-Major Axis [AU]",
"Eccentricity", "Planet Mass [Earths]",
"Planet Radius [Earths]", "Optical Magnitude", "Distance From
Earth [Parsecs]", "Planet Density [g/cm3]")
ui <- fluidPage(
includeScript(path = "bubbs1.js"),
selectInput(inputId = "two", label = "Data Field", choices = columnList, selected = "Distance From Earth [Parsecs]"),
d3Output("d3")
)
server <- function(input, output) {
output$d3 <- renderD3({
if (input$two == "Orbital Period [days]"){
r2d3(data = planets[,c(10,3)], script = "bubbs1.js", d3_version = "4")
}
if (input$two == "Orbital Semi-Major Axis [AU]"){
r2d3(data = planets[,c(10,4)], script = "bubbs1.js", d3_version = "4")
}
if (input$two == "Eccentricity"){
r2d3(data = planets[,c(10,5)], script = "bubbs1.js", d3_version = "4")
}
if (input$two == "Planet Mass [Earths]"){
r2d3(data = planets[,c(10,6)], script = "bubbs1.js", d3_version = "4")
}
if (input$two == "Planet Radius [Earths]"){
r2d3(data = planets[,c(10,7)], script = "bubbs1.js", d3_version = "4")
}
if (input$two == "Optical Magnitude"){
r2d3(data = planets[,c(10,8)], script = "bubbs1.js", d3_version = "4")
}
if (input$two == "Distance From Earth [Parsecs]"){
r2d3(data = planets[,c(10,9)], script = "bubbs1.js", d3_version = "4")
}
r2d3(data = planets[,c(10,9)], script = "bubbs1.js", d3_version = "4")
})
}
shinyApp(ui = ui, server = server)
Firstly, I just want the reactivity in the drop-down menu to work, and I will design the rest if you can help me with this functionality. Eventually, I want to have it be interactive (on click functions like bubble changes color, displays output text box).