Greeting Everyone,
I am newbie to ML...i have been learning to built model based on Keras in R and integrating with Shiny app. My test project that i am trying to built is to classify images of forms that receive for processing in my organization. CNN model I have built works fine when loading model in R Script for Prediction. However when try to load the model in Shiny app, i am getting an error
Error: argument "filepath" is missing, with no default
Below is the code of shiny app that i am trying built. Please help with understanding what i am doing incorrectly.
Note: I have tried to call model from within server function / outside of the as well. Both produce the same error.
library(shiny)
library(keras)
library(EBImage)
library(reticulate)
#pmodel <- load_model_weights_hdf5("E:\Sriram\shiny\image_classifier.h5")
ui <- fluidPage("Hello World",
fileInput(inputId = "imgfile",label = "Upload Your Image file",accept = c(".jpg",".jpeg")),
imageOutput("Page"),
"Printing Results",
textOutput("result")
)
server <- function(input,output)
{
output$Page <- renderImage({
src <- input$imgfile
src <- src$datapath
list(src = src,
height = "300",
alt = "This is alternate text")
})
output$result <-renderText({
pmodel <- load_model_weights_hdf5("E:\Sriram\shiny\image_classifier.h5")
img<-readImage(input$imgfile)
rimg <- img
rimg<-resize(rimg,100,100)
x <- array_reshape(rimg,c(1,100,100,3))
prob <- pmodel %>%
predict_proba(x)
pred <- pmodel%>%
predict_classes(x)
c<-c('HCFA','UB','Dental','Superbill-HCFA','Superbill-UB','Medicare', 'COB', 'Attach','Blank','EOB','MEOB')
paste("Image uploaded is -> %s Page with accuary of %s %%",c[pred])
})
}
shinyApp(ui = ui, server = server)`library(shiny)
I was able to find solution for error. Instead of loading weights, I used load_model_hdf5 function for calling in shiny.
Related
I am trying to create a shiny app to render the 3d point cloud, but I am not sure where to start. Can anyone please help with an example?
Tried the following code but it is giving me pop up
library(shiny)
library(lidR)
library(rlang)
library(rgl)
library(ggplot2)
library(rglwidget)
las<-readLAS("S://change_detction//Snow_on//points (6).las")
str(las)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("LiDAR Visualisation"),
# Sidebar with a slider input for number of bins
rglwidgetOutput("plot", width = 800, height = 600)
# Show a plot of the generated distribution
#mainPanel(
#rglwidgetOutput("distPlot",width = 300, height = 300)
)
# Define server logic required to draw a histogram
server <- function(input, output,session) {
output$plot<- renderRglwidget({
rgl.open()
# generate bins based on input$bins from ui.R
plot(las)
rglwidget()
})
}
# Run the application
shinyApp(ui = ui, server = server)
Is there a way to align the row names of a Rhandsontable in a Shiny app? I only found an argument to adjust the width (rowHeaderWidth), but not the alignment of the row names separately from the body of the table that I know can be done with hot_col(). If it's not possible using the rhandsontable() function, what should the CSS code be?
Simple Shiny example:
library(shiny)
library(rhandsontable)
ui <- fluidPage(
rHandsontableOutput('table')
)
server <- function(input,output,session)({
output$table <- renderRHandsontable({
rhandsontable(mtcars, rowHeaderWidth = 200)
})
})
shinyApp(ui = ui, server = server)
If you see screenshot 01 from browser inspection that you need to change text-align.
you can create style.css file and link the file in app (see screenshot 02)
I just wanted to make the data (displayed in the shiny datatable) selected by user editable and eventually to save the user's updates to a file (e.g. such as an excel file), see the testing code below:
I checked the example/questions below(and a few others), but none of those used the reactive as the data source.
https://yihui.shinyapps.io/DT-edit/
Edit datatable in shiny with dropdown selection (for DT v0.19)
DT: Dynamically change column values based on selectinput from another column in R shiny app
The issue for the code below is: when I try to update the second cell, the updates I made in the first cell disappeared.
library(shiny)
library(DT)
#>
#> Attaching package: 'DT'
#> The following objects are masked from 'package:shiny':
#>
#> dataTableOutput, renderDataTable
ui <- fluidPage(
selectInput("data", "Select a dataset:", choices = c("iris", "mtcars")),
DTOutput("t1"),
actionButton("save", "Save")
)
server <- function(input, output, session) {
tempdf <- NULL
data <- reactive({
head(get(input$data))
})
output$t1 <- renderDT({
data()
}, editable = "cell")
proxyt1 <- dataTableProxy("t1")
observeEvent(input$t1_cell_edit, {
info <- input$t1_cell_edit
str(info)
tempdf <<- editData(data(), info)
# tempdf <<- editData(isolate(data()), info)
replaceData(proxyt1, tempdf, resetPaging = FALSE)
})
# observeEvent(input$save, {
# writexl::write_xlsx(tempdf, "~/test.xlsx")
# })
}
shinyApp(ui, server)
#> PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.
Shiny applications not supported in static R Markdown documents
Created on 2022-05-23 by the reprex package (v2.0.1)
Thank you very much for your help.
I'am using the R package plotly in my shiny application.
Here is a small example:
library(shiny)
library(plotly)
ui <- fluidPage(
plotlyOutput("plot"),
verbatimTextOutput("event")
)
server <- function(input, output) {
# renderPlotly() also understands ggplot2 objects!
output$plot <- renderPlotly({
plot_ly(mtcars, x = ~mpg, y = ~wt)
})
output$event <- renderPrint({
d <- event_data("plotly_hover")
if (is.null(d)) "Hover on a point!" else d
})
}
shinyApp(ui, server)
When I click on the icon to download the graphic, the name of the graphic is "newplot":
How can I change the name "newplot(27)" by for example "ResultDNA(27)"
Thanks.
Currently there are two solutions:
By using export function in plotly
App1 <- plot_ly()
export(App1 , file = "ResultDNA(27).png")
You can 1st save the image in HTML and then in desired format using htmlwidgets
App2 <- plot_ly(...)
htmlwidgets::saveWidget(App2, file = "ResultDNA(27).html")
I have programmed a shiny app in RStudio using R version 3.2.4. The app can be found here: https://koenvandenberge.shinyapps.io/tempConditioning/
Note that there is quite a lot of data to be loaded so it takes a couple of seconds to load.
I have deployed it on my Macbook and it seems as if it only works on Safari and Chromium browsers. It does not seem to work on Chrome or Firefox browsers. With this I mean that the plots which should be generated are not. The drop-down menu is present as it should be, so the app does not crash, but the plots that should be generated by selecting something from the drop-down menu do not.
Is there any way to fix this? You can find the code of my app below:
library(shiny)
library(scales)
load("countMatrix.RData")
countMatrixAllSub = as.data.frame(countMatrix$counts[,-1]) ; rm(countMatrix)
sampleNames = unlist(lapply(strsplit(colnames(countMatrixAllSub),split=".",fixed=TRUE), function(x) x[4]))
sampleNames[28] <- "3c0a"
treat=substr(sampleNames,2,2)
time=substr(sampleNames,3,nchar(sampleNames)-1)
timeC=as.numeric(time)
timeC[timeC==15]=0.25
ui <- shinyUI(fluidPage(
# Application title
titlePanel("Gene expression: conditioning experiment Gust"),
# Sidebar with a
sidebarLayout(
sidebarPanel(
selectInput("gene",
"Pick a gene",
choices = rownames(countMatrixAllSub))
),
# Show a plot of the generated distribution
mainPanel(
plotOutput("genePlot")
)
)
))
# Define server logic required to draw an expression plot
server <- shinyServer(function(input, output) {
output$genePlot <- renderPlot({
par(mar = c(5.1, 4.1, 3, 1))
plot(y=countMatrixAllSub[input$gene,],x=timeC, col=c("black","red")[as.numeric(factor(treat))], pch=19,cex=.6,xaxt="n",xlab="Time", ylab="Expression")
lines(x=unique(timeC[!timeC==0]),y=colMeans(sapply(unique(timeC[!timeC==0]), function(t) as.matrix(countMatrixAllSub[input$gene,treat=="c" & timeC==t]))), col=1)
lines(x=unique(timeC[!timeC==0]),y=colMeans(sapply(unique(timeC[!timeC==0]), function(t) as.matrix(countMatrixAllSub[input$gene,treat=="t" & timeC==t]))), col=2)
axis(1,at=c(0,0.25,1,3,6,9),labels=c("","15m","1h","3h","6h","9h"))
abline(v=c(0,0.25,1,3,6,9),col=alpha("grey",.6))
mtext("Conditioned",side=3, adj=0,col="red")
mtext("Unconditioned",side=3, adj=0.2, col="black")
})
})
# Run the application
shinyApp(ui = ui, server = server)