r - 为什么操作按钮无法正常工作,以及如何在我的应用程序中添加进度条?
问题描述
我闪亮的应用程序上的问题是操作按钮不起作用,当我单击它不运行的按钮时。我用神经网络创建了闪亮的应用程序来分类数据集。我还想在我的应用程序中添加 withprogress。我试过但失败了。谢谢,对不起我的英语不好
这是我的ui.R
library(shiny)
library(shinycssloaders)
library(shinyWidgets)
library(shinythemes)
# Define UI
shinyUI(fluidPage(
theme = shinytheme("superhero"),
tags$head(tags$style(".header{background-image:url('tes3.jpg')}
#title{
color: white;
text-align: center;
} ")),
tags$div(class="header",
titlePanel(
fluidRow(
column(3, img(height = 80, width = 80, src = "undip.png")),
column(5, tags$div(id="title","Klasifikasi Neural Network Dengan Alghoritm Backpropagation")),
column(2),
column(1, img(height = 80, width = 195, src = "statistika.png"))
)
),
tags$style(HTML("
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_processing,
.dataTables_wrapper .dataTables_paginate {
color: #ffffff;
}
thead {
color: #ffffff;
}
tbody {
color: #000000;
}
"
))
),
sidebarLayout(
sidebarPanel(
h4(strong("Tentang Aplikasi"),style="text-align:center"),
div(
p("Gui ini digunakan untuk melakukan klasifikasi data biner
dengan menggunakan jaringan syaraf tiruan dengan
optimasi Backpropagation.",style="text-align:center")
),
# Input: Select a file ----
fileInput("file1", h1("Choose CSV File",align="center",
style = "font-size:30px;"),
multiple = FALSE,
accept = c("text/csv",
"text/comma-separated-values,text/plain",
".csv")),
# Horizontal line ----
tags$hr(),
# Input: Checkbox if file has header ----
checkboxInput("header", "Header", TRUE),
# Input: Select separator ----
radioButtons("sep", "Separator",
choices = c(Comma = ",",
Semicolon = ";",
Tab = "\t"),
selected = ","),
# Input: Select quotes ----
radioButtons("quote", "Quote",
choices = c(None = "",
"Double Quote" = '"',
"Single Quote" = "'"),
selected = '"'),
),
mainPanel(
tags$head(
tags$style(type='text/css',
".nav-tabs {font-size: 20px} ")),
tabsetPanel(
tabPanel("Data", span(style = "color:white",
DT::dataTableOutput("contents"))),
tabPanel("Analisis",
uiOutput("respon",),
conditionalPanel("Fungsi Aktivasi",
selectInput("activhid", "Fungsi Aktivasi Hidden Layer:",
choices= c("logistic", "tanh"))
),
numericInput('train', 'Persentase Data Training (%) :',80),
numericInput('hidden', 'Jumlah Neuron Di Hidden Layer:',10),
numericInput('stepmax', 'Jumlah Iterasi Maksimal:',1e6),
numericInput('lrate', 'Nilai Learning Rate:',0.01),
numericInput('threshold', 'Nilai Threshold:',0.01),
numericInput("randseed",
"Random seed:",
sample(1:1e5, size= 1)),
br(),
actionButton("action", "Predict!")
),
tabPanel("Hasil", withSpinner(verbatimTextOutput("hasil"))),
tabPanel("Nilai Prediksi", div(style = "color:black;font-size: 50%; width: 50%",withSpinner(DT::dataTableOutput("prediksi")))),
tabPanel("Plot",
h4(strong("Arsitektur Neural Network"),style="text-align:center"),
withSpinner(plotOutput("plot1", width = "100%"))
)
)
)
),
hr(),
div(
p("~~~Copyright@2019~~~",style="text-align:center"),
p("By Gustiyan Islahuzaman ",style="text-align:center")
)
)
)
这是我的服务器.R
library(shiny)
library(neuralnet)
library(OneR)
library(caret)
library(DT)
shinyServer(function(input, output,session) {
dInput <- reactive({
in.file <- input$file1
if (is.null(in.file)){
return(NULL)
}else
df <- read.csv(input$file1$datapath,
header = input$header,
sep = input$sep,
quote = input$quote)
})
output$contents <- DT::renderDataTable({
d.input <- datatable(dInput(),class = 'cell-border stripe')
d.input
})
output$respon <- renderUI({
df <- dInput()
if (is.null(df)) return(NULL)
items=names(df)
names(items)=items
selectInput("respon","Memilih Variabel Respon:",items)
})
observeEvent(input$action,{
set.seed(input$randseed)
f <- reactive({as.formula(paste(input$respon, "~ ."))})
actfct = reactive({paste(input$activhid)})
hid =reactive({as.numeric(paste(input$hidden))})
lrate=reactive({as.numeric(paste(input$lrate))})
d <-as.data.frame(req(dInput()))
d[,input$respon] <- as.integer(d[,input$respon])
d <- na.omit(d)
normalize <- function(x) {
return ((x - min(x)) / (max(x) - min(x)))
}
d<-as.data.frame(lapply(d, normalize))
sampel<-reactive({ sample(1:nrow(d), (input$train/100) * nrow(d))})
train<-d[sampel(),]
test<- d[-sampel(),]
fit <-reactive({ neuralnet(f(), data = train,algorithm = "backprop",learningrate =lrate() ,
hidden = hid(),act.fct =actfct(),lifesign = "full",linear.output=FALSE)
})
output$hasil<-renderPrint({
pred<- round(predict(fit(), test))
nn<-fit()
print(nn$result.matrix)
out=eval_model(pred, test)
})
output$plot1<-renderPlot({
plot(fit(),rep="best")
})
output$prediksi<-DT::renderDataTable({
pred<-round(predict(fit(), test))
tabel<-cbind(Nilai_Aktual=test[,input$respon],NIlai_Prediksi=c(pred))
})
})
})
解决方案
推荐阅读
- javascript - Highcharts 饼图高度自动调整大小,包括图例
- html - 如何更改 html 中标题的字体系列?
- r - 排序固定次数
- docker - 如何将 docker 容器地址映射到自定义的“redis://redis:6379”主机?
- python - 如何将具有较小形状的张量分散到较大的张量?
- javascript - 然后在promise外部声明变量,然后在promise内部初始化,然后在promise外部访问
- php - 第一次尝试我正在处理登录/注册表单。收到错误
- javascript - 如何通过使用键值对将两个具有两种不同大小的对象数组合并到一个数组中?
- apache-spark - Spark 事件日志 HDFS 一致性
- android - 检测 USB OTG 设备何时断开连接