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")
Related
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.
Wanted to check if I can convert server.R file into HTML. Sample server file below
server.R
library(shiny)
shinyServer(function(input, output) {
output$greeting <- renderText({
paste0("Hello, ", input$name, "!")
})
print(getwd())
})
You can, try shinyAce. See my example below. It not only gives you the nice html box around it and also r syntax highlight.
library(shiny)
library(shinyAce)
# load your server file for the right path
server_text <- readLines("server.R")
ui <- fluidPage(
aceEditor(outputId = "show_server", value = server_text, readOnly = TRUE, mode = "r")
)
server <- function(input, output) {}
shinyApp(ui = ui, server = server)
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.
I am building an app that presents a data table and which allows you to add data. The adding of data is build by means of a form. This form is written by a module. What I want to happen is that one may fill out the form, press an 'add' button and that the data inside the table is updated.
As an example, could you help me figure out how to complete the following piece of code:
library(shiny)
library(shinydashboard)
moduleInput <- function(id){
ns <- NS(id)
sidebarPanel(
actionButton(ns("action1"), label = "click")
)
}
module <- function(input, output, session){
observeEvent(input$action1, {
# Do stuff here,
# -> let the parent module or server know that something has happened
})
}
ui <- fluidPage(
verbatimTextOutput("module.pressed"),
moduleInput("first")
)
server <- function(input, output, session){
# print the currently open tab
output$module.pressed <- renderPrint({
#-> Write that we have pressed the button of the module
})
callModule(module,"first")
}
shinyApp(ui = ui, server = server)
All I thus want to do is find an easy way to present TRUE in the output field module.pressed when something happend inside the module.
Thanks!
Modules can pass reactive expression(s) to calling apps/modules by returning them in their server function. The documentation provides a few examples on how to set up interactions between modules and calling apps - https://shiny.rstudio.com/articles/modules.html
If a module needs to use a reactive expression, take the reactive expression as a function parameter. If a module wants to return reactive expressions to the calling app, then return a list of reactive expressions from the function.
library(shiny)
moduleInput <- function(id){
ns <- NS(id)
sidebarPanel(
actionButton(ns("action1"), label = "click")
)
}
module <- function(input, output, session){
action1 <- reactive(input$action1)
return(reactive(input$action1))
}
ui <- fluidPage(
verbatimTextOutput("module.pressed"),
moduleInput("first")
)
server <- function(input, output, session){
action1 <- callModule(module,"first")
output$module.pressed <- renderPrint({
print(action1())
})
}
shinyApp(ui = ui, server = server)