在R中创建选定项目的购物车
我在和R一起工作。 在应用程序中,我有一个散点图。在散点图上选择点时,将显示一个表(表1),其中包含所选点的信息。然后,您可以从表1中进行选择,以显示第二个表(表2),其中包含关于从表1中选择的信息。我试图将表2中的选定项目添加到另一个表(表3),但我希望在生成新表2和表1时,这些项目仍保留在表3中。基本上,我想添加多个项目到一个“购物车”下载 在R Shinny中是否有这样做的方法? 下面是我的服务器代码的剪贴在R中创建选定项目的购物车,r,shiny,R,Shiny,我在和R一起工作。 在应用程序中,我有一个散点图。在散点图上选择点时,将显示一个表(表1),其中包含所选点的信息。然后,您可以从表1中进行选择,以显示第二个表(表2),其中包含关于从表1中选择的信息。我试图将表2中的选定项目添加到另一个表(表3),但我希望在生成新表2和表1时,这些项目仍保留在表3中。基本上,我想添加多个项目到一个“购物车”下载 在R Shinny中是否有这样做的方法? 下面是我的服务器代码的剪贴 server <- shinyServer(function(input,
server <- shinyServer(function(input, output, session) {
######scatter plot
output$landscape_scatter <- renderPlotly({
p <- plot_ly(data = data, x = ~X, y = ~Y,
color= ~get(input$landscape_color),
type="scatter"
)
p
})
####### table 1
output$selected.data.table <- DT::renderDataTable({
d <- event_data("plotly_selected")
if (is.null(d))
return()
x_min <- round(min(d$x), 5)-0.00001
x_max <- round(max(d$x),5)+0.00001
y_min <- round(min(d$y), 5)-0.00001
y_max <- round(max(d$y), 5)+0.00001
sel.data <- subset(data, X >= x_min &
X <= x_max &
Y >= y_min &
Y <= y_max)
sel.data <- sel.data[,c(37,6,33)]
sel.data$cluster <- as.integer(sel.data$cluster)
table.data <- DT::datatable(sel.data[,c(4,1,2)], class = 'compact', width = "100%", rownames = FALSE, escape=c(-1), selection = c("single")
)
table.data
})
###### table 2
output$data2 <- DT::renderDataTable({
d <- event_data("plotly_selected")
if (is.null(d))
return()
x_min <- round(min(d$x), 5)-0.00001
x_max <- round(max(d$x),5)+0.00001
y_min <- round(min(d$y), 5)-0.00001
y_max <- round(max(d$y), 5)+0.00001
sel.data <- subset(data, X >= x_min &
X <= x_max &
Y >= y_min &
Y <= y_max)
sel.data <- sel.data[,c(37,6,33)]
sel.data$cluster <- as.integer(sel.data$cluster)
data2 <- card[which(card$NUMBER %in% sel.data[input$selected.data.table_rows_selected,2]),c(1,3,11,14)]
table.data <- DT::datatable(data2)
)
table.data
})
})
shinyApp(ui = ui, server = server)
服务器欢迎来到SO!请为我们提供一个完整的可复制示例(不仅仅是服务器功能)。欢迎使用SO!请向我们提供一个完整的可复制示例(不仅仅是服务器功能)。