Hi everyone,
I've scoured the internet for a straight answer to my, in my oppinion, simple question but none really worked.
I want to plots to be displayed in my shinyapp.
Plot 1: a 3d scatter plot (from plotly)
Plot 2: a plot based on a dataframe that was filtered by an attribute of a dot clicked in Plot 1
I want to click on a dot in plot 1which then induces the generation of plot 2.
The rough backbone of what I have so far:
ui <- fluidPage(
titlePanel('Protein level analysis'),
sidebarLayout(
sidebarPanel(
fileInput('protein_table', 'Select a protein table'),
),
mainPanel(
plotlyOutput('scatter_3d'),
plotOutput('selected_protein_details')
)
)
)
server <- function(input, output) {
protein_tab <- reactive({import_table_from_anywhere(input$protein_table$datapath, separator = ',', header = TRUE)}) # importing the table this way works with a self written, customized import function. This works
output$scatter_3d <- renderPlotly({ # the first plot appears in my shiny app, no problem until here
req(input$protein_table$datapath)
ploty = plot_ly(x = protein_tab()$column1,
y = protein_tab()$column2,
z = protein_tab()$column3,
marker = list(size = 3),
hovertext = paste0(protein_tab()$description, "<br>", protein_tab()$uniprot_id),
source = "uniprot_id") %>%
layout(scene = list(yaxis = list(title = "Column2", autorange = "reversed"),
xaxis = list(title = "Column1"),
zaxis = list(title = "Column3")),
height = 700)
})
output$selected_protein_details = renderPlot({
filtered_protein_tab = filter(protein_tab(), ??????? ## I'd like to filter the imported table by the uniprot_id column of the data point I clicked
plot2_table = function_to_wrangle_filtered_protein_tab(filtered_protein_tab)
ggplot(plot2_table, mapping = aes(.........)) # the second output plot
}
# Run the app ----
shinyApp(ui = ui, server = server)
I read a lot about event_data(), bindEvent(), using source = "xyz" in the plotly plot, and some more stuff but I just can't make sense of it. It seems like it should be a trivial thing to implement.
Any help is appreciated! Thanks!