'Using radio button selections for a plot in Shiny
I'm attempting to make a widget on Shiny where two axes are selected to make a plot. My first thought was to make a data frame and radio buttons that select columns out of it. It's not working so far, and I'm not sure what is missing. What I'm starting with is:
library(shiny)
library(shinydashboard)
df <- data.frame(set_1=c(1,4,4,2,10,5),
set_2=c(20,30,25,20,70,60),
set_3=c(8,18,20,12,22,15))
db <- dashboardPage(
dashboardHeader(title='My Dashboard'),
dashboardSidebar(),
dashboardBody(
fluidRow(
box(
plotOutput('p1',height=250)
),
box(
title='Select x axis',
radioButtons('radio_x',
choices=list('Set 1'='set_1',
'Set 2'='set_2',
'Set 3'='set_3'))
),
box(
title='Select y axis',
radioButtons('radio_y',
choices=list('Set 1'='set_1',
'Set 2'='set_2',
'Set 3'='set_3'))
)
)
)
)
server <- function(input,output){
output$p1 <- renderPlot({
p_data <- data.frame(x_axis=get(input$radio_x),y_axis=get(input$radio_y))
plot(p_data$x_axis,p_data$y_axis)
})
}
shinyApp(db,server)
The box where the plot is supposed to go says "Error: object 'list(1
= "1", 2
= "2", 3
= "3")' not found"
Any clues what needs to change here?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|