앱을 실행하면 기본 화면에 오류가 발생합니다. 앱이 작동 할 때 오류에 대해 걱정하지 않습니다. 입력을 선택하면 앱이 잘 작동합니다.
내가하고 싶은 것은 기본 화면에서 오류를 숨기는 것입니다. 이것은 내가 받고있는 오류 메시지입니다.
Error: <text>:2:0: unexpected end of input
1: admit ~
^
앱을 반응 형으로 유지하고 싶기 때문에이 문제를 해결하는 버튼을 추가하고 싶지 않습니다. 하지만 버튼을 추가하고 반응 형을 유지하는 방법이 있다면 그 아이디어가 마음에 듭니다.
또한 "종속 및 독립 변수 선택"또는 이와 유사한 것과 같은 기본 화면에 사용자 지정 메시지를 표시하는 아이디어에 열려 있습니다.
library(shiny)
mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv")
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("input1", "Dependent Variable", choices = names(mydata)),
selectInput("input2", "Independent Variable(s)", choices = names(mydata), multiple = TRUE)
),
mainPanel(
verbatimTextOutput("output2"),
verbatimTextOutput("output1")
)
)
)
server <- function(input, output) {
left_vars <- reactive({input$input1})
right_vars <- reactive({
rights = input$input2
rights <- paste(rights, collapse=" + ")
})
log_formula <- reactive({as.formula(paste(left_vars(), " ~ ", right_vars()))})
output$output1 <- renderPrint({summary(glm(formula = log_formula(), data = mydata, family = "binomial"))})
output$output2 <- renderPrint({
paste(paste0(left_vars(), " ~", right_vars()))
})
}
shinyApp(ui = ui, server = server)
반응 용어에 유효성 검사를 추가하면 조건문이있는 사용자 지정 오류 메시지를 작성할 수 있습니다.
library(shiny)
mydata <- read.csv("https://stats.idre.ucla.edu/stat/data/binary.csv")
ui <- fluidPage(
sidebarLayout(
sidebarPanel(
selectInput("input1", "Dependent Variable", choices = names(mydata)),
selectInput("input2", "Independent Variable(s)", choices = names(mydata), multiple = TRUE)
),
mainPanel(
verbatimTextOutput("output2"),
verbatimTextOutput("output1")
)
)
)
server <- function(input, output) {
left_vars <- reactive({
validate(
need(input$input1, "Please enter a dependant variable"))
input$input1})
right_vars <- reactive({
validate(
need(input$input2, "Please enter an independant variable"))
rights = input$input2
rights <- paste(rights, collapse=" + ")
})
log_formula <- reactive({as.formula(paste(left_vars(), " ~ ", right_vars()))})
output$output1 <- renderPrint({summary(glm(formula = log_formula(), data = mydata, family = "binomial"))})
output$output2 <- renderPrint({
paste(paste0(left_vars(), " ~ ", right_vars()))
})
}
shinyApp(ui = ui, server = server)
편집 : 동일한 경고가 두 번 표시되는 이유가 궁금한 경우. 독립 변수가 선택 될 때까지 완료 할 수없는 렌더링 기능이 두 개 있기 때문입니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다