Skip to content

Instantly share code, notes, and snippets.

@wolf6541
Last active December 30, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolf6541/7874968 to your computer and use it in GitHub Desktop.
Save wolf6541/7874968 to your computer and use it in GitHub Desktop.
library(shiny)
library(dfcrm)
library(Epi)
#controle des dates
data_time = read.table("Z:/Programmation_R/Appli_Shiny/fichier excel/fichier_1.csv",header = T, sep = ";")
data_time$dat_num <- as.Date(data_time$Date_inclusion, format="%d/%m/%Y" )
day_date = Sys.Date()
data_time$dat_num = data_time$dat_num - day_date
data_time$dat_num =abs(data_time$dat_num)
data_control = min(data_time$dat_num)
#preparation des données crm
data_time$rep_bin[data_time$reponse == "Succes"] = 1
data_time$rep_bin[data_time$reponse == "Echec"] = 0
#Crm
prior <- c(0.05, 0.10, 0.20, 0.35, 0.50, 0.70)
target <- 0.3
level <- data_time$Dose
y <- data_time$rep_bin
foo <- crm(prior, target, y, level)
ptox <- foo$ptox # updated estimates of toxicity rates
dose = c(1,2,3,4,5,6)
#2 décimales après la virgule
prior = round(prior,2)
ptox = round(ptox,2)
#Construction tableau 1
data = cbind(dose,prior,ptox)
data = as.data.frame(data)
data_tableau1 = data
data_tableau1$dose = as.factor(data_tableau1$dose)
data_tableau1 = t(data_tableau1)
data_tableau1 = as.data.frame(data_tableau1)
names(data_tableau1) <- NULL
#choix de la dose optimale
data$tox_opt = data$ptox - 0.3
data$tox_opt = abs(data$tox_opt)
best_dose = data$dose[data$tox_opt == min(data$tox_opt)]
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {
#Liste des tables
datasetInput <- reactive({
switch(input$dataset,
"Observations" = data_tableau1,
"Historique" = data_time[-c(7,6)],)
})
#affichage du tableau
output$view <- renderTable({
head(datasetInput(), n = length(data))
})
# Show the first "n" observations
output$view <- renderTable({
head(datasetInput(), n = input$obs)
})
#Graphique
output$plot <- renderPlot({
plot(data$prior ~ data$dose,type = "b",col = "red",ylim =c(0,1),xlab = "Dose", ylab = "Probability of response or Toxicity")
par(new = T)
plot(data$ptox ~ data$dose,type ="b",col = "blue",xaxt='n',ylim =c(0,1),
yaxt='n',ann=FALSE)
legend("topleft", legend = c("Initial toxicity", "Modified toxicity"), col = c("red", "blue"),
pch = 15, bty = "n",lty=c(1,1),
horiz = TRUE, inset = c(0.1, 0.1))
abline(h=0.30,lwd=2)
})
})
library(shiny)
library(dfcrm)
library(Epi)
#controle des dates
data_time = read.table("Z:/Programmation_R/Appli_Shiny/fichier excel/fichier_1.csv",header = T, sep = ";")
data_time$dat_num <- as.Date(data_time$Date_inclusion, format="%d/%m/%Y" )
day_date = Sys.Date()
data_time$dat_num = data_time$dat_num - day_date
data_time$dat_num =abs(data_time$dat_num)
data_control = min(data_time$dat_num)
#preparation des données crm
data_time$rep_bin[data_time$reponse == "Succes"] = 1
data_time$rep_bin[data_time$reponse == "Echec"] = 0
#Crm
prior <- c(0.05, 0.10, 0.20, 0.35, 0.50, 0.70)
target <- 0.3
level <- data_time$Dose
y <- data_time$rep_bin
foo <- crm(prior, target, y, level)
ptox <- foo$ptox # updated estimates of toxicity rates
dose = c(1,2,3,4,5,6)
#2 décimales après la virgule
prior = round(prior,2)
ptox = round(ptox,2)
#Construction tableau 1
data = cbind(dose,prior,ptox)
data = as.data.frame(data)
data_tableau1 = data
data_tableau1$dose = as.factor(data_tableau1$dose)
data_tableau1 = t(data_tableau1)
data_tableau1 = as.data.frame(data_tableau1)
names(data_tableau1) <- NULL
#choix de la dose optimale
data$tox_opt = data$ptox - 0.3
data$tox_opt = abs(data$tox_opt)
best_dose = data$dose[data$tox_opt == min(data$tox_opt)]
# Define UI for dataset viewer application
shinyUI(pageWithSidebar(
#Application title.
headerPanel("OPTIMUM TRIAL"),
sidebarPanel(
#Menu des tables
selectInput("dataset", "Choisir une table:",
choices = c("Observations", "Historique")),
#Nombre D'observation
numericInput("obs", "Number of observations to view:", 10),
#Bouton de mise à jours
submitButton("Update View")
),
mainPanel(
h4("Observations"),
tableOutput("view"),
if ( data_control < 15 )
h3("ceci est une phrase de test")
else
h3(paste("la dose recommandee est la dose ",best_dose)),
#Affichage du graphique
plotOutput("plot")
)
))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment