如何将server.r引入全局环境?

如何将server.r引入全局环境?,r,shiny,R,Shiny,在下面的代码中,我希望将输出$click带到全局环境中 最后,我希望直接使用选定的值 是否可以使用鼠标以x、y的形式选择的值,即使在闪亮应用程序终止时也是如此 ui <- fluidPage( radioButtons("plotType", "Plot Type:", choices = c("ggplotly", "plotly")), plotlyOutput("plot" ), verbatimTextOutput("click"), verbatimTextOutput

在下面的代码中,我希望将输出$click带到全局环境中

最后,我希望直接使用选定的值

是否可以使用鼠标以x、y的形式选择的值,即使在闪亮应用程序终止时也是如此

ui <- fluidPage(

radioButtons("plotType", "Plot Type:", choices = c("ggplotly", "plotly")),

plotlyOutput("plot"

),

verbatimTextOutput("click"),

verbatimTextOutput("brush")

)

server <- function(input, output, session) {

output$plot <- renderPlotly({

# use the key aesthetic/argument to help uniquely identify selected observations

key <- row.names(mtcars)

if (identical(input$plotType, "ggplotly")) {

p <- ggplot(data, aes(x = c(1:nrow(data)) , y = y, colour = factor(WF_ID), key = LOT_CODE)) +

geom_line(color="black") + geom_point()

ggplotly(p) %>% layout(dragmode = "select")

} else {

plot_ly(data, x = ~c(1:nrow(data)), y = ~y, key = ~data$LOT_CODE, mode = 'lines+markers') %>%

layout(dragmode = "select")

}

})

output$click <- renderPrint({

d <- event_data("plotly_click")

if (is.null(d)) "Click events appear here (double-click to clear)" else d

})

}

ui正如@HubertL提到的,使用
免责声明:有些人会认为这不是好的做法。虽然可以使用操作符
将数据从服务器传输到全局环境,但也可以使用
assign
envir
参数