0

I have an existing Shiny script with standard widgets from the Shiny library. Now I wish to add something to show temperature on a graphical scale? This would be a read-only value, so it wouldn't make sense to use a slider unless the slider can be locked and only changed programatically. Is that possible? If not, what are other suggestions?


To clarify:

Is it possible to have a Shiny slider as read only. The user can not slide it but it can be programmatically changed. Here is a Shiny slider:

library(shiny)

ui <- fluidPage(

  sliderInput("aa", "Temp",
              min = -20, max = 20,
              value = 10, step = 10)
)

server <- function(input, output) { }

shinyApp(ui, server)

I'm not familiar with Shiny Dashboard but I saw taskItem. Can these be "dropped in" and used with a normal Shiny app that uses fluidPage, sidebarPanel, mainPanel? How does one remove the bullet point and the percentage? Here is an example of a taskItem.

library(shiny)
library(shinydashboard)

ui <- dashboardPage(

  dashboardHeader(),
  dashboardSidebar(),
  dashboardBody(
    taskItem(value = temp <- 89, color = "red",
                                      "Temp"
                             ))
)

server <- function(input, output) { }

  temp <- 89

shinyApp(ui, server)

enter image description here

ixodid
  • 2,180
  • 1
  • 19
  • 46
  • Add it as an image? – Vishesh Shrivastav Sep 16 '18 at 02:40
  • I don't know what other help can be provided unless you provide a little more information. On SO, we prefer fully *reproducible examples*, where we can better see what you are trying to do and give you something relevant to your situation. Refs: https://stackoverflow.com/questions/5963269/, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Sep 16 '18 at 03:06
  • See clarification. – ixodid Sep 16 '18 at 04:50

2 Answers2

0

AFAIK, sliderInput cannot be used as an output. However here's a potential solution using progressBar from shinyWidgets package

library(shiny)
library(shinyWidgets)

ui <- fluidPage(
  sidebarLayout(
    sidebarPanel(
      h3("Sidebar")
    ),
    mainPanel(
      br(), br(), br(),
      progressBar("tempbar", value = 0, title = "Temperature", status = "danger")
    )
  )
)

server <- function(input, output, session) {
  temp <- 89
  updateProgressBar(session, id = "tempbar", value = temp)
}
shinyApp(ui, server)

shiny app with temperature bar

Replace temp in server with whatever calculated value you might have. For fixed temperature value just set it in ui, no need to use updateProgressBar. By default progressBar is scaled from 0-100. To modify see documentation for it.

Shree
  • 10,835
  • 1
  • 14
  • 36
0

You can use updateSliderInput to achieve such an behaviour. Couple this with shinyjs::disabled and you get what you want. I would however look for a less hackish solution:

library(shiny)
library(shinyjs)

ui <- fluidPage(
  ## add style to remove the opacity effect of disabled elements
  tags$head(
    tags$style(HTML("
                    .irs-disabled {
                       opacity: 1      
                    }")
              )
  ),
  useShinyjs(),
  disabled(sliderInput("aa", "Temp",
                       min = -20, max = 20,
                       value = 10, step = 10)),
  actionButton("Change", "Change")
)

server <- function(input, output, session) {
  observeEvent(input$Change, {
    new_temp <- sample(seq(-20, 20, 10), 1)
    updateSliderInput(session, "aa", value = new_temp)
  })
}

shinyApp(ui, server)
thothal
  • 16,690
  • 3
  • 36
  • 71