Passing dynamic input and updating visual in R shiny - r

The script below when executed creates a process_map() with a select input. Upon selecting a resource like "r1","r2" etc. we get the corresponding process map. However I want to dynamically pass an input from the selectInput bar and update the process map within R shiny page Snapshot for your reference. Please help.
## app.R ##
install.packages("bupaR")
install.packages("edeaR")
install.packages("eventdataR")
install.packages("processmapR")
install.packages("processmonitR")
install.packages("xesreadR")
install.packages("petrinetR")
install.packages("shiny")
install.packages("shinydashboard")
library(shiny)
library(shinydashboard)
library(bupaR)
library(edeaR)
library(eventdataR)
library(processmapR)
library(processmonitR)
library(xesreadR)
library(petrinetR)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
selectInput("resources","Select the resource", c("r1","r2","r3","r4","r5"),
selected = "r1",selectize = T)
),
dashboardBody(
filter_resource(patients,resources = c("r1","r2","r4"), reverse = F) %>%
process_map()
))
server <- function(input, output) {
}
shinyApp(ui, server)

You could do
library(shiny)
library(shinydashboard)
library(bupaR)
library(edeaR)
library(eventdataR)
library(processmapR)
library(processmonitR)
library(xesreadR)
library(petrinetR)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
selectInput("resources","Select the resource", c("r1","r2","r3","r4","r5"),selected = "r1",selectize = T)
),
dashboardBody(
uiOutput("ui")
))
server <- function(input, output) {
output$ui <- renderUI({
r <- input$resources
tagList(filter_resource(patients,resources = r, reverse = F) %>% process_map())
})
}
shinyApp(ui, server)

Related

Shiny seesion object is not found when trying to use shinyJS()

In the shiny app below Im trying to use shinyJS() to hide and display text but I get:
Error: shinyjs: could not find the Shiny session object. This usually happens when a shinyjs function is called from a context that wasn't set up by a Shiny session.
Do not bother that dataset does not exist its just an example
## app.R ##
library(shiny)
library(shinydashboard)
library(dplyr)
library(shinyjs)
ui <- dashboardPage(
dashboardHeader(title = "Biodiversity"),
dashboardSidebar(
actionButton("action","Submit")
),
dashboardBody(
useShinyjs(),
show(
div(id='text_div',
verbatimTextOutput("text")
)
),
uiOutput("help_text"),
plotlyOutput("plot")
)
)
server <- function(input, output) {
output$help_text <- renderUI({
HTML("<b>Click 'Show plot' to show the plot.</b>")
})
react<-eventReactive(input$action,{
hide("help_text")
omited <-subset(omited, omited$scientificName %in% isolate(input$sci)&omited$verbatimScientificName %in% isolate(input$ver))
})
}
shinyApp(ui = ui, server = server)
You can't use show() in the ui, these functions are used in the server. Remove that and it works. Sample:
## app.R ##
library(shiny)
library(shinydashboard)
library(dplyr)
library(shinyjs)
library(plotly)
ui <- dashboardPage(
dashboardHeader(title = "Biodiversity"),
dashboardSidebar(
actionButton("action","Submit")
),
dashboardBody(
useShinyjs(),
div(id='text_div',
verbatimTextOutput("text")
)
,
uiOutput("help_text"),
plotOutput("plot")
)
)
server <- function(input, output) {
output$help_text <- renderUI({
HTML("<b>Click 'Show plot' to show the plot.</b>")
})
observeEvent(input$action,{
hide("help_text")
output$plot <- renderPlot({
plot(1)
})
})}
shinyApp(ui = ui, server = server)
Output:

Implementing span to click on plot and move in R shiny

The given code creates a simple scatterPlot. I wish to click on the plot and move it in any direction that I want to, basically the span functionality. Attached the snapshot for references.Please help and thanks.
## app.R ##
library(shiny)
library(shinydashboard)
library(bupaR)
library(edeaR)
library(eventdataR)
library(processmapR)
library(processmonitR)
library(xesreadR)
library(lubridate)
library(dplyr)
library(knitr)
library(XML)
library(xml2)
library(data.table)
library(ggplot2)
library(ggthemes)
library(glue)
library(tibble)
library(miniUI)
library(tidyr)
library(shinyTime)
library(petrinetR)
library(magrittr)
library(shinyWidgets)
library(DiagrammeR)
ui <- dashboardPage(
dashboardHeader(title = "Zoom and Reset Dashboard",titleWidth = 290),
dashboardSidebar(
width = 0
),
dashboardBody(
# Creation of tabs and tabsetPanel
tabsetPanel(type = "tab",
tabPanel("Resource Dashboard",
fluidRow(column(10,
grVizOutput("res_freq_plot")))),
id= "tabselected"
)
))
server <- function(input, output)
{
output$res_freq_plot <- renderDiagrammeR(
{
patients %>% process_map()
}
)
}
shinyApp(ui, server)
You can use plotly
## app.R ##
library(shiny)
library(plotly)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(title = "Zoom and Reset Dashboard",titleWidth = 290),
dashboardSidebar(
width = 0
),
dashboardBody(
# Creation of tabs and tabsetPanel
tabsetPanel(type = "tab",
tabPanel("Resource Dashboard",
fluidRow(column(10,
plotlyOutput("res_freq_plot")))),
id= "tabselected"
)
))
server <- function(input, output)
{
output$res_freq_plot <- renderPlotly(
{
plot_ly(iris, x= iris$Petal.Length, y = iris$Sepal.Length)
}
)
}
shinyApp(ui, server)

Replicating selectInput plot using sliderInput

the given script updates the process_map() plot in R shiny using
selectInput. I wish to replicate the same functionality using a sliderInput.
library(shiny)
library(shinydashboard)
library(bupaR)
library(edeaR)
library(eventdataR)
library(processmapR)
library(processmonitR)
library(xesreadR)
library(petrinetR)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(
selectInput("resources","Select the resource",
c("r1","r2","r3","r4","r5"),selected = "r1",selectize = T, multiple = T)
),
dashboardBody(
uiOutput("ui")
))
server <- function(input, output) {
output$ui <- renderUI({
r <- input$resources
tagList(filter_resource(patients,resources = r, reverse = F) %>%
process_map())
})
}
shinyApp(ui, server)
I just realized the slider needed numeric input to update the plot, hence incorporated the same
sliderInput("activities", "Select the activities", 0.1, 1.0, 0.1 )
It is working fine for my own problem.

Shiny R checkboxGroupInput selected all

I have a checkboxGroupInput in my Shiny app with the following code :
checkboxGroupInput("sexe", "Sexe:",
c("Masculin" = "mas","FĂ©minin" = "fem"))
My question is how to have them checked when first loaded?
knowing that I've tried selected= c but didn't work
use selected = c("mas","fem")
For example
library(shiny)
library(shinydashboard)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody( checkboxGroupInput("sexe","Sexe:",
choices = c("Masculin" = "mas", "Femenin" = "fem"),
selected = c("mas","fem")))
)
server <- function(input, output){
}
shinyApp(ui, server)

gvisGeoChart with shiny Dashboard

Unable to get output for givsGeoChart in my shiny Dashboard.
Below is the code for the same.
library(shiny)
library(shinydashboard)
library(googleVis)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
htmlOutput("Accidents")
)
)
server <- function(input, output) {
output$Accidents <- renderGvis({
gvisGeoChart(Dum, "States","Road_Accident",
options=list(region="IN",displayMode="regions",resolution="provinces",width="100%"))
})
}
shinyApp(ui, server)
The above code doesn't work.
GeoStates_IN <- gvisGeoChart(Dum, "States","Road_Accident",options=list(region="IN",displayMode="regions",resolution="provinces",width="100%"))
plot(GeoStates_IN)
whereas this code works.Unable to figure out what is missing in above code.
Any kind of help is appreciated.
Problem has something to do with your options() or data. Is your variable dum cotaining columns "States" and "Road_Accident". Have you included the data in server.R?
This works:
library(shiny)
library(shinydashboard)
library(googleVis)
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody(
htmlOutput("Accidents")
)
)
server <- function(input, output) {
output$Accidents <- renderGvis({
data(Exports)
#map<-gvisGeoChart(Exports, "States","Road_Accident",
#options=list(region="IN",displayMode="regions",resolution="provinces",width="100%"))
map<-gvisGeoChart(Exports, locationvar='Country', colorvar='Profit',
options=list(projection="kavrayskiy-vii"))
return(map)
})
}
shinyApp(ui, server)

Resources