通过过程使用输出到php

时间:2019-06-01 14:42:44

标签: php

我写了一个代码来验证和删除数据库中的记录。我现在需要使用此代码的输出到php中并进行打印。有人可以帮我在php中定义吗

该过程是用MariaDB编写的

ui <- fluidPage(
  actionButton(inputId = 'Go', label = 'Go'),
  actionButton(inputId = 'Go2', label = 'Go2'),
  plotlyOutput('RFAcc_FP1',  width = 450)

)

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


  observeEvent(input$Go, { 
    values$RFImp_FP1 <- data.table(MeanDecreaseAccuracy =  runif(10, min = 0, max = 1), Variables = letters[1:10])
    values$RFImp_FP1$Selected <- 1
  })

observeEvent(input$Go2,{

  values$RFImp_FP1$Selected[1:4] <- 1-values$RFImp_FP1$Selected[1:4] 
  print(values$RFImp_FP1$Selected)
})

observe({
  if(!is.null(values$RFImp_FP1)) {
    parsToChange <- event_data("plotly_selected", source = 'RFAcc_FP1')$y
    if(!is.null(event_data("plotly_selected", source = 'RFAcc_FP1'))){
      data_df <- values$RFImp_FP1
      data_df <- data_df %>% .[, Selected := if_else(Variables %in% parsToChange, 1-Selected, Selected)]
      values$RFImp_FP1$Selected <- data_df$Selected
    print(values$RFImp_FP1)
      }
  }
})
observeEvent(values$RFImp_FP1, { 
  print('seeing change')
  })


output$RFAcc_FP1 <- renderPlotly({

  values$RFImp_FP1
  if(!is.null(values$RFImp_FP1)) {

    RFImp_score <- values$RFImp_FP1[order(MeanDecreaseAccuracy)]
    plotheight <- length(RFImp_score$Variables) * input$testme
    p <- plot_ly(data = RFImp_score,
                 source = 'RFAcc_FP1',
                 height = plotheight,
                 width = 450)  %>%
      add_trace(x = RFImp_score$MeanDecreaseAccuracy,
                y = RFImp_score$Variables,
                type = 'scatter',
                mode = 'markers',
                color = factor(RFImp_score$Selected),
                colors = c('#1b73c1', '#797979'),
                symbol = factor(RFImp_score$Selected),
                symbols = c('circle','x'),
                marker = list(size  = 6),
                hoverinfo = "text",
                text = ~paste ('<br>', 'Parameter: ', RFImp_score$Variables,
                               '<br>',  'Mean decrease accuracy: ', format(round(RFImp_score$MeanDecreaseAccuracy*100, digits = 2), nsmall = 2),'%',
                               sep = '')) %>%
      layout(
        margin = list(l = 160, r= 20, b = 70, t = 50),
        hoverlabel = list(font=list( color = '#1b73c1'), bgcolor='#f7fbff'),
        xaxis =  list(title = 'Mean decrease accuracy index (%)',
                      tickformat = "%",
                      showgrid = F,
                      showline = T,
                      zeroline = F,
                      nticks = 5,
                      font = list(size = 8),
                      ticks = "outside",
                      ticklen = 5,
                      tickwidth = 2,
                      tickcolor = toRGB("black")
        ),
        yaxis =  list(categoryarray = RFImp_score$Variables,
                      autorange = T,
                      showgrid = F,
                      showline = T,
                      autotick = T,
                      font = list(size = 8),
                      ticks = "outside",
                      ticklen = 5,
                      tickwidth = 2,
                      tickcolor = toRGB("black")
        ),
        dragmode =  "select"
      ) %>%  add_annotations(x = 0.5,
                             y = 1.05,
                             textangle = 0,
                             font = list(size = 14,
                                         color = 'black'),
                             text = "Contribution to accuracy",
                             showarrow = F,
                             xref='paper',
                             yref='paper')


    p$elementId <- NULL   ## to surpress warning of widgetid
    p <- p %>% config(displayModeBar = F)
    p

  } else {
    p <- plot_ly( type = 'scatter', mode = 'markers',  height = '400px', width = 450) %>% layout(
      margin = list(l = 160, r= 20, b = 70, t = 50),
      xaxis = list(title = 'Mean decrease accuracy index', range= c(0,1), nticks = 2, showline = TRUE),
      yaxis = list(title = 'Model input variables', range = c(0,1), nticks = 2, showline = TRUE)) %>%
      add_annotations(x = 0.5, y = 1.1, textangle = 0, font = list(size = 14, color = 'black'),
                      text = 'Contribution to accuracy',
                      showarrow = F, xref='paper', yref='paper')
    p$elementId <- NULL
    p <- p %>% config(displayModeBar = F)
    p}
})


}
shinyApp(ui, server)

0 个答案:

没有答案